[求助]注册验证的错误
<P>弄了个小小的注册验证 不太明白,在网上找了些代码改了改。<BR>一共三个文件ajax.js,checkuser.jsp,test.jsp<BR>第一个是:ajax.js<BR>//定义XMLHttpRequest对象实例<BR>var http_request = false;<BR>//定义可重复使用的HTTP请求函数<BR>function send_request(method,url,content,responseType,callback){<BR> ////初始化、指定处理函数、发送请求的函数<BR> http_request = false;<BR> //初始化XMLHttpRequest对象<BR> if(window.XMLHttpRequest){<BR> http_request = new XMLHttpRequest();<BR> if(http_request.overrideMimeType){<BR> //设置MIME类型<BR> http_request.overrideMimeType("text/xml");<BR> }<BR> }else if(window.ActionXObject){<BR> //IE浏览器<BR> try{<BR> http_request = new ActionXObject("Msxml2.XMLHTTP");<BR> }catch(e){<BR> try{<BR> http_request = new ActionXObject("Microsoft.XMLHTTP");<BR> }catch(e){}<BR> }<BR> }<BR> <BR> if(!http_request){<BR> // 异常,创建对象实例失败<BR> window.alert('对不起! 不能创建XMLHttpRequest对象!');<BR> return false;<BR> }<BR> if(responseType.toLowerCase()=="text"){<BR> http_request.onreadystatechange=="callback";<BR> }else(responseType.toLowerCase()=="xml"){<BR> http_request.onreadystatechange=="callback";<BR> }else{<BR> window.alert("相应类型参数错误!");<BR> return false;<BR> }<BR> // 确定发送请求的方式和URL以及是否异步执行下段代码<BR> if(method.toLowerCase()=="get"){<BR> http_request.open(method,url,true); <BR> }else if(method.toLowerCase()=="post"){<BR> http_request.open(method, url, true);<BR> http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");<BR> }else {<BR> window.alert("http请求类别参数错误。");<BR> return false;<BR> }<BR> http_request.send(content);<BR>}</P><P><BR>// 处理返回文本格式信息的函数<BR>function processTextResponse(){<BR> if(http_request.readyState==4){<BR> if(http_request.status==200){<BR> window.alert("Text文档响应。");<BR> }else{<BR> window.alert("您所请求的页面有异常。");<BR> }<BR> }<BR>}</P>
<P>//处理返回的XML格式文档的函数<BR>function processXMLResponse() {<BR> if (http_request.readyState == 4) { // 判断对象状态<BR> if (http_request.status == 200) { // 信息已经成功返回,开始处理信息<BR> //alert(http_request.responseXML);<BR> alert("XML文档响应。");<BR> } else { //页面不正常<BR> alert("您所请求的页面有异常。");<BR> }<BR> }<BR>}<BR>第二个文件:test.jsp<BR><%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %><BR><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" target="_blank" >http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</A>"><BR><html xmlns="<a href="http://www.w3.org/1999/xhtml" target="_blank" >http://www.w3.org/1999/xhtml</A>"><BR><head><BR><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><BR><title>无标题文档</title><BR></head><BR><script language="text/javascript" src="ajax.js"></script><BR><script language="text/javascript"></P>
<P> function myAlert(strTitle){<BR> var message = document.getElement.getElementById("myDiv").innerHTML;<BR> var winl = new Zapatec.AlertWindow(message, {title:strTitle, modal:true, width : 580,height:330});<BR> }<BR> function doCheck(){<BR> //var f = document.forms[0];<BR> if(document.form1.username.value!="") {<BR> document.getElementById("feedback_info").innerHTML = "系统正在处理您的请求,请稍后。";<BR> send_request("GET","checkuser.jsp?username="+document.form1.username.value,null,"text",showFeedbackInfo);<BR> }<BR> else {<BR> document.getElementById("feedback_info").innerHTML = "请输入用户名称。";<BR> }</P>
<P> }<BR> <BR> function showFeedbackInfo() {<BR> if (http_request.readyState == 4) { // 判断对象状态<BR> if (http_request.status == 200) { // 信息已经成功返回,开始处理信息<BR> document.getElementById("feedback_info").innerHTML = http_request.responseText;<BR> } else { //页面不正常<BR> alert("您所请求的页面有异常。");<BR> }<BR> }<BR>}</P>
<P></script><BR><body><BR><form id="form1" name="form1" method="get" action=""><BR> <table align="center" width="248" border="1" cellpadding="0" cellspacing="0"><BR> <tr><BR> <td height="31" colspan="2"><div align="center">注册测试</div></td><BR> </tr><BR> <tr><BR> <td width="86" height="19">用户名:</td><BR> <td width="156"><div align="center"><BR> <input name="username" type="text" size="10" onblur="doCheck()" /><BR> </div></td><BR> </tr><BR> <tr><td colspan="2"><span id="feedback_info" style="color:#FF0000"></span></td><BR> <tr></P>
<P> <tr><BR> <td height="20">密 码 :</td><BR> <td><div align="center"><BR> <input name="password" type="text" id="password" size="10" /><BR> </div></td><BR> </tr><BR> <tr><BR> <td height="32">&nbsp;</td><BR> <td><input type="submit" name="Submit" value="提交" /><BR> <input type="reset" name="Submit2" value="重置" /></td><BR> </tr><BR> </table><BR></form></P>
<P></body><BR></html><BR>第三个是:checkuser.jsp<BR><%@ page contentType="text/html; charset=GBK" language="java" import="java.sql.*" errorPage="" %><BR><%@ include file="/login_check.jsp" %><BR><%@ page import="com.zwh.tools.*" %><BR><%@ include file="/includes/base_new.jsp" %><BR><%<BR> String username = request.getParameter("username");<BR> sql = "select * from yhgl where zh='"+username+"'";<BR> System.out.println(sql+"OOOOOOOOOOOOOOO");<BR> pstmt = conn.parepareStatement(sql);<BR> rs = pstmt.executeQuery();<BR> if(rs.next()){<BR> out.println("用户名称["+username+"]已经被注册,请更换其他用户名称再注册。");<BR> }else{<BR> out.println("恭喜您!用户名称["+username+"]尚未被注册,您可以继续。");<BR> }<BR> DBUtils.closeConn(pstmt, rs);<BR>%><BR><%@ include file="/includes/end_new.jsp" %><BR>一直提示对象为空。<BR>请教哪位帮我看看 万分感谢。。。。[em01]</P>
页:
[1]
