各位前輩大神,客戶端部分我想我寫的雖然不成熟,但應(yīng)該沒問題,服務(wù)器部分怎么響應(yīng),怎么以XML格式或其他格式響應(yīng)客戶端,這我無(wú)從下手,求指點(diǎn)!??!JSP中的JS代碼如下:if(dom)的位置不反應(yīng),它前面的alert(dom)是undefined。<script?type="text/javascript">
???? $(document).ready(function(){
???? $("input[name='usercode']").blur(function(){
???? var?xmlHttpRequest=false;
???? if(window.XMLHttpRequest){//返回為true說明是新版本IE或其他瀏覽器
???? xmlHttpRequest=new?XMLHttpRequest();
???? }else{//返回值為false時(shí),說明是老板本IE
???? xmlHttpRequest=new?ActieXObject("Microsoft.XMLHTTP");
???? }
???? //初始化組件
???? var?url="<%=path%>/DoCheckServlet";alert("d")
???? xmlHttpRequest.open("post",url,true);
//設(shè)置回調(diào)函數(shù)
xmlHttpRequest.onreadystatechange=callback;
function?callback(){
if?(xmlHttpRequest.readyState?==?4
&&?xmlHttpRequest.status?==?200)?{alert(1);
var?dom?=?xmlHttpRequest.responseXML;//獲取服務(wù)器端返回的XML形式的文檔對(duì)象
alert(2);alert(dom);
if?(dom)?{
//獲取節(jié)點(diǎn)名為usercode的節(jié)點(diǎn)對(duì)象集合
var?userNodes=dom.getElementsByTagName("usercode");
if(yserNodes.length>0){
var?username=userNodes[0].firstChild.nodeValue;
$("input[name=usercode]").attr("value",username);
alert(2);
}
}
}
}
//發(fā)送請(qǐng)求
var?usercode=$("[name=usercode]").val();
xmlHttpRequest.send(usercode);
});
});
</script>下面是DoCheckServlet的代碼,未完成,我寫不下去了,跪求指點(diǎn)?。?!public?class?DoCheckServlet?extends?HttpServlet?{
public?void?doPost(HttpServletRequest?request,?HttpServletResponse?response)
throws?ServletException,?IOException?,Exception{
//?獲取頁(yè)面參數(shù)
String?userCode?=?request.getParameter("usercode");
String?passWord=null;
String?path?=?(String)?request.getAttribute("path");
//?調(diào)用業(yè)務(wù)邏輯接口,用戶登錄
IUserService?userService?=?new?UserServiceImpl();
//獲取數(shù)據(jù)庫(kù)中所有的用戶集合
List<Users>?userlist=userService.query(usercode);
//下面該怎么將這個(gè)集合以XML格式傳到JSP頁(yè)面中的AJAX
}
}
1 回答
已采納

tom的貓
TA貢獻(xiàn)65條經(jīng)驗(yàn) 獲得超35個(gè)贊
將userList轉(zhuǎn)成js可解析的格式,這里推薦使用json
PrintWriter?out?=?response.getWriter(); ?
out.write(jsonArray.toString());?
- 1 回答
- 0 關(guān)注
- 1718 瀏覽
添加回答
舉報(bào)
0/150
提交
取消