http.js
1
var HTTP =
{
2
xmlHttp : null,
3
callBack : function (content)
{},
4
createXMLHttpRequest : function ()
{
5
if(window.ActiveXObject)
{
6
this.xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
7
}
8
else if(window.XMLHttpRequest)
{
9
this.xmlHttp = new XMLHttpRequest();
10
}
11
},
12
get : function (url)
{
13
this.createXMLHttpRequest();
14
try
{
15
this.xmlHttp.open("GET",url,true);
16
this.xmlHttp.onreadystatechange = this.startCallback;
17
this.xmlHttp.send(null);
18
}catch(e)
{alert(e.message);}
19
},
20
startCallback : function ()
{
21
if(HTTP.xmlHttp.readyState == 4)
{
22
if(HTTP.xmlHttp.status == 200)
{
23
HTTP.callBack(HTTP.xmlHttp.responseText);
24
}
25
}
26
}} xml.js
1
var maxPage = 1;
2
var XMLDATA =
{
3
data : "",
4
num : 0,
5
page : 0,
6
pageSize : 12,
7
literals : new Array("确定要删除?","确定要执行操作?"),
8
waite : function()
{
9
if(""==this.data && this.num<5)
{
10
setTimeout("XMLDATA.waite()",100);
11
this.num++;
12
}else if(this.num==5)
{
13
alert("err");
14
}else
{
15
var p = new DOMParser();
16
try
{
17
var doc = p.parseFromString(this.data,"text/xml");
18
}catch(e)
{return;}
19
this.parse(doc);
20
}
21
},
22
initialize : function (u)
{
23
if(window.DOMParser)//firefox内核的浏览器
24

{
25
HTTP.callBack = function (content)
{
26
XMLDATA.data = content;
27
};
28
HTTP.get(u);
29
setTimeout("XMLDATA.waite()",100);
30
return true;
31
}
32
else if( window.ActiveXObject )//ie内核的浏览器
33

{
34
this.data = "Microsoft";
35
var doc = new ActiveXObject( "Microsoft.XMLDOM" );
36
doc.async = false;
37
doc.load(u);
38
this.parse(doc);
39
return true;
40
}
41
else
42
return false;
43
},
44
searchclass : function ()
45

{
46
document.all.pageadd.value = 0;
47
this.getteach();
48
},
49
xmlRefresh : function ()
{
50
this.getteach(document.all.pageadd.value);
51
},
52
$ : function (f)
{
53
return document.getElementById(f);
54
},
55
execute : function (url)
{
56
XMLDATA.$("showXml").innerHTML = "正在执行操作
";
57
HTTP.callBack = function (content)
{
58
if(content=="1")
59
XMLDATA.$("showXml").innerHTML = "操作成功,正在加载数据
";
60
else
61
XMLDATA.$("showXml").innerHTML = "操作失败,正在加载数据
";
62
setTimeout("XMLDATA.xmlRefresh()",1000);
63
};
64
HTTP.get(url);
65
},
66
getteach : function (fun)
{
67
this.$("showXml").innerHTML = "正在加载数据
";
68
var n;
69
n = parseInt(document.all.pageadd.value);
70
if(isNaN(parseInt(fun)))
{
71
if(fun == "sub")
{n = n - 1;}else
{n = n + 1;}
72
}else
{
73
n = parseInt(fun);
74
}
75
this.displayPre(!(n <= 1));
76
this.displayNext(false);
77
document.all.pageadd.value = n;
78
this.page = n;
79
var xmlurl = "/user/xml.htm?method="+method+"&n="+n;
80
if(typeof(userId)!="undefined")xmlurl += "&userId="+userId;
81
if(typeof(args)!="undefined" && args!=null)xmlurl += "&"+args;
82
if(!this.initialize(xmlurl))
{
83
this.$("showXml").innerHTML = "没有找到任何数据!";
84
}else
{
85
86
}
87
},
88
getNodeText : function(nodes,o)
{
89
return nodes.getElementsByTagName(o)[0].firstChild.nodeValue;
90
},
91
nextNode : function(root,i)
{
92
return root.childNodes[i];
93
},
94
getAttribute : function(node,name)
{
95
for(i=0;i<node.attributes.length;i++)
96
if(name==node.attributes[i].name)
97
return node.attributes[i].value;
98
return null;
99
},
100
getNodeName : function(node)
{
101
return node.nodeName;
102
},
103
getNodeValue : function(node)
{
104
return node.firstChild.nodeValue;
105
},
106
parse : function(xmldoc)
{
107
var n = this.page;
108
var xmlroot = xmldoc.documentElement;
109
var showStr = '<table width="90%" border="0" cellspacing="0" cellpadding="0">';
110
var j,i,num;
111
var node = xmlroot.childNodes.length;
112
var nodes;
113
i = 0;
114
while(i != node)
{
115
showStr += "<tr>";
116
nodes = this.nextNode(xmlroot,i);
117
if(i == 0)
118
{
119
maxPage = this.getNodeText(nodes,"page");
120
this.pageSize = parseInt(this.getNodeText(nodes,"size"));
121
this.displayNext(!(node<this.pageSize));
122
document.all.pagecount.innerHTML = '第 '+n+' 页'+'(共'+this.getNodeText(nodes,"page")+'页)';
123
}
124
this.displayNext(maxPage>1 && n<maxPage);
125
if(nodes == null)
126
{
127
showStr += '</tr></table>';
128
this.$("showXml").innerHTML = showStr;
129
return;
130
}
131
j=0;
132
nodes_its = nodes.childNodes;
133
num = nodes_its.length;
134
while(j != num)
{
135
nnn = this.nextNode(nodes,j);
136
j++;
137
if(nnn == null)
138
{
139
break;
140
}
141
if(this.getNodeName(nnn)!="pro")continue;
142
showStr += "<td>";
143
if(this.getAttribute(nnn,"url")!=null)
{
144
showStr += "<a ";
145
this.getAttribute(nnn,"confirm")=="true"?
146
showStr +="href=\"javaScript:;\" onClick=\"XMLDATA.confirm('"+this.getAttribute(nnn,"url")+"',XMLDATA.literals["+this.getAttribute(nnn,"literal")+"]);\">"
147
:showStr +="href=\""+this.getAttribute(nnn,"url")+"\" target='_blank'>";
148
showStr += this.getNodeValue(nnn);
149
showStr += "</a>";
150
}else
{showStr += this.getNodeValue(nnn);}
151
showStr += '</td>';
152
}
153
showStr += '</tr>';
154
i++;
155
}
156
showStr += '</table>';
157
if(showStr == '<table width="90%" border="0" cellspacing="0" cellpadding="0"></table>')
158
{this.$("showXml").innerHTML = "没有找到任何数据!";if(this.page>1)this.getteach(this.page-1);}
159
else
160
{this.$("showXml").innerHTML = showStr;}
161
},
162
displayNext : function (flag)
{
163
if(flag)
164
{document.all.next.style.display = "";
165
document.all.next2.style.display = "";}else
166
{document.all.next.style.display = "none";
167
document.all.next2.style.display = "none";}
168
},
169
displayPre : function (flag)
{
170
if(flag)
171
{document.all.pre.style.display = "";
172
document.all.pre2.style.display = "";}
173
else
174
{document.all.pre.style.display = "none";
175
document.all.pre2.style.display = "none";}
176
},
177
confirm : function (url,literal)
{
178
if(!confirm(literal)) return false;
179
XMLDATA.execute(url);
180
}
181
}
182
window.onload = function()
{XMLDATA.searchclass();}; JAVA类
1
public class XmlHelper
{
2
PrintWriter pw;
3
private boolean startItemed = false;
4
private boolean endItemed = true;
5
private boolean endRooted = false;
6
private boolean inited = false;
7
private int page;
8
private int pageSize;
9
private int defaultPageSize = 20;
10
private static final int LITERAL_DELETE = 0;
11
private static final int LITERAL_OPERATE = 1;
12
13
public XmlHelper(PrintWriter pw, int totalPage)
{
14
this.pw = pw;
15
this.pw.write("<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
16
endRooted = false;
17
this.page = totalPage;
18
this.pageSize = defaultPageSize;
19
}
20
21
public XmlHelper(PrintWriter pw, int totalPage,int size)
{
22
this.pw = pw;
23
this.pw.write("<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
24
endRooted = false;
25
this.page = totalPage;
26
this.pageSize = size;
27
}
28
29
public void startItem()
{
30
if (endRooted)
31
throw new XMLException("root already end!");
32
if (!endItemed)
33
throw new XMLException("previous item not end!");
34
pw.write("<item>");
35
startItemed = true;
36
endItemed = false;
37
}
38
39
public void endItem()
{
40
if (endRooted)
41
throw new XMLException("root already end!");
42
if (!startItemed)
43
throw new XMLException("the item not start!");
44
if(!inited)
{
45
pw.write("<page>");
46
pw.write(page + "");
47
pw.write("</page>");
48
pw.write("<size>");
49
pw.write(pageSize + "");
50
pw.write("</size>");
51
inited = true;
52
}
53
pw.write("</item>");
54
startItemed = false;
55
endItemed = true;
56
}
57
58
public void writeText(String text)
{
59
if (endRooted)
60
throw new XMLException("root already end!");
61
pw.write("<pro><![CDATA[");
62
pw.write(trip(text));
63
pw.write("]]></pro>");
64
}
65
66
public void writeText(String url, String text)
{
67
if (endRooted)
68
throw new XMLException("root already end!");
69
pw.write("<pro");
70
pw.write(" url=\"");
71
pw.write(trip(url));
72
pw.write("\"><![CDATA[");
73
pw.write(trip(text));
74
pw.write("]]></pro>");
75
}
76
77
public void writeConfirmText(String url, String text)
{
78
if (endRooted)
79
throw new XMLException("root already end!");
80
pw.write("<pro");
81
pw.write(" url=\"");
82
pw.write(trip(url));
83
pw.write("\" confirm=\"true\" literal=\""+LITERAL_DELETE+"\"><![CDATA[");
84
pw.write(trip(text));
85
pw.write("]]></pro>");
86
}
87
88
/** *//**
89
* @param url
90
* @param text
91
* @param lan (LAN_DELETE)
92
*/
93
public void writeConfirmText(String url, String text, int literal)
{
94
if (endRooted)
95
throw new XMLException("root already end!");
96
pw.write("<pro");
97
pw.write(" url=\"");
98
pw.write(trip(url));
99
pw.write("\" confirm=\"true\" literal=\""+literal+"\"><![CDATA[");
100
pw.write(trip(text));
101
pw.write("]]></pro>");
102
}
103
104
private String trip(String text)
{
105
return text==null?"":text;
106
}
107
108
public void end()
{
109
if (endRooted)
110
throw new XMLException("root already end!");
111
pw.write("</root>");
112
endRooted = true;
113
}
114
115
public class XMLException extends RuntimeException
{
116
public XMLException(String message)
{
117
super(message);
118
}
119
}
120
} 1
public ActionForward comment(ActionMapping mapping, ActionForm form,
2
HttpServletRequest request, HttpServletResponse response)
3
throws Exception
{
4
String n = request.getParameter("n");
5
int pageNo = 1;
6
if ((n == null) || ((pageNo = Integer.valueOf(n)) <= 0))
{
7
pageNo = 1;
8
}
9
int pageSize = defaultPageSize;
10
UserService service = (UserService) getService("userService");
11
long userId = getUserId(request);
12
List<ArticleCommentInfo> listPapooseCommonList = service
13
.getPapooseCommonUserList(pageNo, pageSize, userId);
14
15
int total = service.getPapooseCommonUserListSeekDonativeList(userId);
16
int totalPage = total / pageSize;
17
int remain = total % pageSize;
18
if (remain > 0)
{
19
totalPage++;
20
}
21
response.setContentType("text/xml");
22
PrintWriter pw = response.getWriter();
23
XmlHelper xmlh = new XmlHelper(pw, totalPage, defaultPageSize);
24
boolean confirm = privilege(request) == 3;
25
for (ArticleCommentInfo pb : listPapooseCommonList)
{
26
xmlh.startItem();
27
xmlh.writeText("["
28
+ (pb.getPapoose().getType() == 0 ? "亲子园" : "幼儿园") + "]");
29
xmlh.writeText(
30
"/papooseSelect/score.htm?method=scorePapoose&papoose.id="
31
+ pb.getPapoose().getId(), pb.getPapoose()
32
.getPapooseName());
33
xmlh.writeText(
34
"/papooseSelect/score.htm?method=scorePapoose&papoose.id="
35
+ pb.getPapoose().getId(), StringUtils.substring(pb
36
.getContent(), 0, 30));
37
xmlh.writeText(DateUtils
38
.formatDate(pb.getIssueDate(), "yyyy-MM-dd"));
39
if (confirm)
40
xmlh.writeConfirmText(
41
"/user/room.htm?method=removePapooseReview&id="
42
+ pb.getId(),
43
"删除");
44
xmlh.endItem();
45
}
46
xmlh.end();
47
return null;
48
} HTML
1
<html xmlns="http://www.w3.org/1999/xhtml">
2
<head>
3
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
4
<title>参与的爱心求助</title>
5
<SCRIPT LANGUAGE="JavaScript">
6
<!--
7
var method = "appeal";
8
//-->
9
</SCRIPT>
10
<SCRIPT LANGUAGE="JavaScript" SRC="/js/http.js"></SCRIPT>
11
<SCRIPT LANGUAGE="JavaScript" SRC="/js/xml.js"></SCRIPT>
12
</head>
13
<body>
14
<table width="100%" border="0" cellspacing="0" cellpadding="0">
15
<tr>
16
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
17
<tr>
18
<td width="118" height="28" align="center" background="/img/micon12.gif" class="cn12a blue03"><STRONG>参与的爱心求助</STRONG></td>
19
<td class="table07"><span class="cn12a"> </span></td>
20
</tr>
21
</table></td>
22
</tr>
23
<tr>
24
<td valign="top" bgcolor="#FFFFFF" class="table08" style="padding:12"><div id="showXml">正在加载中
</div></td>
25
</tr>
26
<tr><td height="38" align="right" style="padding-right:6" class="cn12a"><input type="hidden"id="search_category"/> <input type="hidden" id="pageadd" value="0"/><span id="pagecount"></span> <span id="pre2"><A href="javaScript:XMLDATA.searchclass();" class="cn12a gry" >[首页]</A></span> <span id="pre"><A href="javaScript:XMLDATA.getteach('sub');" class="cn12a gry">[上一页]</A></span> <span id="next"><A href="javaScript:XMLDATA.getteach('in');" class="cn12a gry">[下一页]</A></span> <span id="next2"><A href="javaScript:XMLDATA.getteach(maxPage);" class="cn12a gry">[末页]</A></span></td>
27
</tr>
28
</table>
29
</body>
30
</html>
posted on 2007-03-01 00:01
盐巴 阅读(697)
评论(0) 编辑 收藏 所属分类:
网站技术