| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 771 人关注过本帖
标题:信息验证出错!!
取消只看楼主 加入收藏
Javapet
Rank: 1
等 级:禁止访问
帖 子:80
专家分:0
注 册:2008-1-5
结帖率:50%
收藏
 问题点数:0 回复次数:1 
信息验证出错!!
为什么我的程序在验证信息时会出现网页错误啊?请指教!谢谢了

页面: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]]
搜索更多相关主题的帖子: var quot str 验证 java 
2008-05-28 13:18
Javapet
Rank: 1
等 级:禁止访问
帖 子:80
专家分:0
注 册:2008-1-5
收藏
得分:0 
没人知道哪里错了吗?
2008-05-31 17:13
快速回复:信息验证出错!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.038534 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved