信息验证出错!!
为什么我的程序在验证信息时会出现网页错误啊?请指教!谢谢了页面:register.jsp
<%@ page language="java" contentType="text/html;charset=GB2312"%>
<script type="text/javascript">
var req;
var mdiv;
var str;
var strr;
function validate(str1,str2,str3)
{
str=str1;
strr=str3;
var idName = document.getElementById(str);
var URL_= "validate.jsp?id="+escape(idName.value)+str2;
if(window.XMLHttpRequest)
{
req = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
req = new ActiveXObject("Microsoft.XMLHTTP");
}
req.open("GET",URL_,true);
req.onreadystatechange = callback;
req.send(null);
}
function callback()
{
if(req.readyState == 4)
{
if(req.status == 200)
{
var msg = req.responseXML.getElementsByTagName("msg")[0];
mdiv = document.getElementById(strr);
if(msg != null&&msg != "")
{
setMsg(msg.childNodes[0].nodeValue);
}
else if(str == "userNameId")
{
mdiv.innerHTML = "<font color='green'>通过</font>";
return;
}
else if(str == "pwordId")
{
mdiv.innerHTML = "<font color='green'>通过</font>";
return;
}
}
}
}
function setMsg(msg)
{
mdiv = document.getElementById(msg);
alert("a");
if(msg == "userNameSpan")
{
mdiv.innerHTML = "<font color='red'>该用户已经存在,请重新填写一个</font>";
return;
}
else if(msg == "pwordSpan")
{
mdiv.innerHTML = "<font color='red'>密码不能为空</font>";
return;
}
}
</script>
<center>
<h1><font color="#9F79EE">注册信息</font></h1>
<hr noshade size=4 color="#9AFF9A">
<form action="register.jsp" method="post">
<input type="hidden" name="action" value="register">
<table border=1 bordercolor="#8968CD" width=90% cellpadding=3 cellspacing=0>
<tr>
<th bgcolor="#8968CD" colspan=2 align="left"><b><font color="white" size=3>注册 - 必填内容</font></b></th>
</tr>
<tr>
<td bgcolor="#F0F8FF"><b><font face="楷体_GB2312" size=3>用户名:</font></b></td>
<td><input id="userNameId" type="text" name="userName" style="background-color:#F0F8FF" onblur="validate(this.id,'userName','userNameSpan')">
<span id=userNameSpan></span></td>
</tr>
<tr>
<td bgcolor="#F0F8FF"><b><font face="楷体_GB2312" size=3>密码:</font></b></td>
<td><input id="pwordId" type="password" name="pword" style="background-color:#F0F8FF" onblur="validate(this.id,'pword','pwordSpan')">
<span id="pwordSpan"></span></td>
</tr>
<tr>
<td bgcolor="#F0F8FF"><b><font face="楷体_GB2312" size=3>确认密码:</font></b></td>
<td><input type="password" name="pword2" style="background-color:#F0F8FF">
<span id="pword2Span"></span></td>
</tr>
<tr>
<td bgcolor="#F0F8FF"><b><font face="楷体_GB2312" size=3>电话:</font></b></td>
<td><input type="text" name="phone" style="background-color:#F0F8FF">
<span id="phoneSpan"></span></td>
</tr>
<tr>
<td bgcolor="#F0F8FF"><b><font face="楷体_GB2312" size=3>送货地址:</font></b></td>
<td><textArea name="address" cols=50 rows=5 wrap="physical" style="background-color:#F0F8FF"></textArea>
<span id="addressSpan"></span></td>
</tr>
</table>
<br><input type="submit" value="提交" onclick="return confirm('真的要提交吗?')">
</form>
</center>
页面:validate.jsp
<%
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-store"); //HTTP1.1
response.setHeader("Pragma", "no-cache"); //HTTP1.0
response.setDateHeader("Expires", 0); //prevents catching at proxy server
String id=request.getParameter("id");
if(id.indexOf("userName") != -1)
{
if(id.indexOf("ff") != -1)
{
response.getWriter().write("<msg>userNameSpan</msg>");
}
}
else if(id.indexOf("pword") != -1)
{
response.getWriter().write("<msg>pwordSpan</msg>");
}
%>
[[it] 本帖最后由 Javapet 于 2008-5-28 13:51 编辑 [/it]]
[[it] 本帖最后由 Javapet 于 2008-5-28 18:31 编辑 [/it]]