| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1500 人关注过本帖
标题:[求助]注册验证的错误
只看楼主 加入收藏
可可℃乐
Rank: 2
等 级:新手上路
威 望:3
帖 子:1054
专家分:0
注 册:2006-5-9
收藏
 问题点数:0 回复次数:0 
[求助]注册验证的错误

弄了个小小的注册验证 不太明白,在网上找了些代码改了改。
一共三个文件ajax.js,checkuser.jsp,test.jsp
第一个是:ajax.js
//定义XMLHttpRequest对象实例
var http_request = false;
//定义可重复使用的HTTP请求函数
function send_request(method,url,content,responseType,callback){
////初始化、指定处理函数、发送请求的函数
http_request = false;
//初始化XMLHttpRequest对象
if(window.XMLHttpRequest){
http_request = new XMLHttpRequest();
if(http_request.overrideMimeType){
//设置MIME类型
http_request.overrideMimeType("text/xml");
}
}else if(window.ActionXObject){
//IE浏览器
try{
http_request = new ActionXObject("Msxml2.XMLHTTP");
}catch(e){
try{
http_request = new ActionXObject("Microsoft.XMLHTTP");
}catch(e){}
}
}

if(!http_request){
// 异常,创建对象实例失败
window.alert('对不起! 不能创建XMLHttpRequest对象!');
return false;
}
if(responseType.toLowerCase()=="text"){
http_request.onreadystatechange=="callback";
}else(responseType.toLowerCase()=="xml"){
http_request.onreadystatechange=="callback";
}else{
window.alert("相应类型参数错误!");
return false;
}
// 确定发送请求的方式和URL以及是否异步执行下段代码
if(method.toLowerCase()=="get"){
http_request.open(method,url,true);
}else if(method.toLowerCase()=="post"){
http_request.open(method, url, true);
http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
}else {
window.alert("http请求类别参数错误。");
return false;
}
http_request.send(content);
}


// 处理返回文本格式信息的函数
function processTextResponse(){
if(http_request.readyState==4){
if(http_request.status==200){
window.alert("Text文档响应。");
}else{
window.alert("您所请求的页面有异常。");
}
}
}

//处理返回的XML格式文档的函数
function processXMLResponse() {
if (http_request.readyState == 4) { // 判断对象状态
if (http_request.status == 200) { // 信息已经成功返回,开始处理信息
//alert(http_request.responseXML);
alert("XML文档响应。");
} else { //页面不正常
alert("您所请求的页面有异常。");
}
}
}
第二个文件:test.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script language="text/javascript" src="ajax.js"></script>
<script language="text/javascript">

function myAlert(strTitle){
var message = document.getElement.getElementById("myDiv").innerHTML;
var winl = new Zapatec.AlertWindow(message, {title:strTitle, modal:true, width : 580,height:330});
}
function doCheck(){
//var f = document.forms[0];
if(document.form1.username.value!="") {
document.getElementById("feedback_info").innerHTML = "系统正在处理您的请求,请稍后。";
send_request("GET","checkuser.jsp?username="+document.form1.username.value,null,"text",showFeedbackInfo);
}
else {
document.getElementById("feedback_info").innerHTML = "请输入用户名称。";
}

}

function showFeedbackInfo() {
if (http_request.readyState == 4) { // 判断对象状态
if (http_request.status == 200) { // 信息已经成功返回,开始处理信息
document.getElementById("feedback_info").innerHTML = http_request.responseText;
} else { //页面不正常
alert("您所请求的页面有异常。");
}
}
}

</script>
<body>
<form id="form1" name="form1" method="get" action="">
<table align="center" width="248" border="1" cellpadding="0" cellspacing="0">
<tr>
<td height="31" colspan="2"><div align="center">注册测试</div></td>
</tr>
<tr>
<td width="86" height="19">用户名:</td>
<td width="156"><div align="center">
<input name="username" type="text" size="10" onblur="doCheck()" />
</div></td>
</tr>
<tr><td colspan="2"><span id="feedback_info" style="color:#FF0000"></span></td>
<tr>

<tr>
<td height="20">密 码 :</td>
<td><div align="center">
<input name="password" type="text" id="password" size="10" />
</div></td>
</tr>
<tr>
<td height="32">&nbsp;</td>
<td><input type="submit" name="Submit" value="提交" />
<input type="reset" name="Submit2" value="重置" /></td>
</tr>
</table>
</form>

</body>
</html>
第三个是:checkuser.jsp
<%@ page contentType="text/html; charset=GBK" language="java" import="java.sql.*" errorPage="" %>
<%@ include file="/login_check.jsp" %>
<%@ page import="com.zwh.tools.*" %>
<%@ include file="/includes/base_new.jsp" %>
<%
String username = request.getParameter("username");
sql = "select * from yhgl where zh='"+username+"'";
System.out.println(sql+"OOOOOOOOOOOOOOO");
pstmt = conn.parepareStatement(sql);
rs = pstmt.executeQuery();
if(rs.next()){
out.println("用户名称["+username+"]已经被注册,请更换其他用户名称再注册。");
}else{
out.println("恭喜您!用户名称["+username+"]尚未被注册,您可以继续。");
}
DBUtils.closeConn(pstmt, rs);
%>
<%@ include file="/includes/end_new.jsp" %>
一直提示对象为空。
请教哪位帮我看看 万分感谢。。。。

搜索更多相关主题的帖子: request ajax 函数 验证 定义 
2007-05-06 14:49
快速回复:[求助]注册验证的错误
数据加载中...
 
   



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

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