建站学院(LieHuo.Net)编程综合 如何在struts框架下使用ajax验证用户名密码?共分为三步。
1、下载一个ajax框架包prototype.js
2、在jsp页面写
以下为引用的内容: function valid() { if(document.forms[0].loginid.value!=document.forms[0].orginLoginid.value){ document.getElementById('echo1').innerHTML = "正在检测登录ID..."; var ajax = new Ajax.Request('/bankInfoAction.do', {method: 'get',parameters:'mode=equalLoginId&loginid=' + document.forms [0].loginid.value,onComplete:callback2}); } else{ document.getElementById('echo1').innerHTML = ""; } } function callback2(originalRequest) { if (originalRequest) if (originalRequest.readyState == 4) { if (originalRequest.status == 200) { if (originalRequest.responseText == "1") { $('echo1').innerHTML = "该登录ID可以使用!"; } else { $('echo1').innerHTML = "<font color=red>该登录ID已存在或不可用!</font>"; var logid=document.forms[0].loginid.value; document.forms[0].loginid.value = ""; document.forms[0].password.value = ""; document.forms[0].password1.value = ""; if(logid!=""){ document.forms[0].loginid.focus(); } } } } } |
以下为引用的内容: if (bankInfoForm.getFlag() == -9) {//这里是判断是否存在,可在command方法里写 write(response, "0", "text/xml", "UTF-8"); } else { write(response, "1", "text/xml", "UTF-8"); // } |