信息验证出错!!

08-05-28 pet

为什么我的程序在验证信息时会出现网页错误啊?请指教!谢谢了

页面:register.jsp
<%@ page language="java" contentType="text/html;charset=GB2312"%>
<script type="text/javascript">
var req;
var mdiv;

function validate(str,str2)
{
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];
setMsg(msg.childNodes[0].nodeValue);
}
}
}

function setMsg(msg)
{
mdiv = document.getElementById(msg);
if(msg == "userNameSpan")
{
mdiv.innerHTML = "<font color='red'>该用户已经存在,请重新填写一个</font>";
return;
}
else
{
mdiv.innerHTML = "<font color='green'>通过</font>";
return;
}
if(msg == "pwordSpan")
{
mdiv.innerHTML = "<font color='red'>密码不能为空</font>";
return;
}
else
{
mdiv.innerHTML = "<font color='green'>通过</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')">
<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')">
<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>");
}
%>

[该贴被pet于2008-05-28 13:51修改过]
[该贴被pet于2008-05-28 14:06修改过]