JAVA-----Ajax实现注册用户名唯一性检查

1 篇文章 0 订阅

通过对HTML输入完毕后,释放编辑框焦点。执行判断是否用户名已被注册的及时提醒操作。

html文本

<%@ page contentType="text/html;charset=GB2312" %>
<html>
<head>
<title>Ajax实现用户注册名唯一性检查</title>
<meta http-equiv="content-type" content="text/html; charset=GB2312">
<style type="text/css">
<!--
.style1 {font-size: 12px}
.style2 {color: #FF0000}
-->
</style>
</head>
<script language="javascript">
var xmlHttpReq=null;
function createRequest(){
if(window.XMLHttpRequest){
xmlHttpReq=new XMLHttpRequest();
}else if(window.ActiveXObject){
xmlHttpReq=new ActiveXOject("Microsft.XMLHTTP");
}
 
}
function getBackInfo(){
createRequest();
var username=document.getElementById("username").value;
if(username.trim().length==0){
document.getElementById("disCheckResult").innerHTML="user no empyt!";
document.getElementById("username").focus();
return false;
}
if(xmlHttpReq!=null){
var url="checkUser.jsp?username="+username;
xmlHttpReq.open("get",url,true);
xmlHttpReq.onreadystatechange=disResult;
xmlHttpReq.send(null);
}else{
alert(":nonononono!!!!");
 
}
 
}
function disResult(){
if(xmlHttpReq.readyState==4){
if(xmlHttpReq.status==200){
alert(xmlHttpReq.responseText);
document.getElementById("disCheckResult").innerHTML=xmlHttpReq.responseText;
 
}else{
alert("eorr!");
}
}
}
</script>
<body>
<form name="form1" method="post" >
<table width="100%" border="0" align="center" bgcolor="#0099FF">
<tr>
<th colspan="3" scope="col"> 用户注册</th>
</tr>
<tr bgcolor="#FFFFFF">
<th width="36%" rowspan="7" scope="row"></th>
<th width="18%" height="46" scope="row"><div align="left">
<span style="font-weight: 400"><font size="2">用户名:</font></span></div></th>
<td width="46%"><input name="username" type="text" οnblur="getBackInfo()" id="username" >
<span class="style2">*</span><span id=disCheckResult style="color:red"> </span> </td>
</tr>
<tr bgcolor="#FFFFFF">
<th height="39" scope="row"><div align="left">
<span style="font-weight: 400"><font size="2">密码:</font></span></div></th>
<td><input name="pwd" type="password" id="pwd">
<span class="style2">*</span></td>
</tr>
<tr bgcolor="#FFFFFF">
<th height="39" scope="row"><div align="left">
<span style="font-weight: 400"><font size="2">确认密码:</font></span></div></th>
<td><input type="password" name="pwd1">
<span class="style2">*</span></td>
</tr>
<tr bgcolor="#FFFFFF">
<th height="39" scope="row"><div align="left">
<span style="font-weight: 400"><font size="2">真实姓名:</font></span></div></th>
<td><input name="header" type="text">
<span class="style2">*</span></td>
</tr>
<tr bgcolor="#FFFFFF">
<th height="39" scope="row"><div align="left">
<span style="font-weight: 400"><font size="2">电话:</font></span></div></th>
<td><input name="phone" type="text">
<span class="style2">*</span></td>
</tr>
<tr bgcolor="#FFFFFF">
<th height="39" scope="row"><div align="left">
<span style="font-weight: 400"><font size="2">电子邮箱:</font></span></div></th>
<td><input name="email" type="text">
<span class="style2">*</span></td>
</tr>
<tr bgcolor="#FFFFFF">
<th height="37" scope="row"> </th>
<td><input type="submit" name="Submit" value="提交">
<input type="reset" name="Reset" value="重填"></td>
</tr>
</table>
</form>
</body>
</html>


java的代码

<%@ page language="java" import="java.util.*,java.sql.*,ajck.aj.*" pageEncoding="utf-8" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
 
<%
String username=request.getParameter("username");
String sql="select * from users where username=’"+username+"’";
ConnDB conn=new ConnDB();
ResultSet rs= conn.doQuery(sql);
if(rs.next()){
out.println("账号已被注册");
}else{
out.println("可以注册");
}
 
%>



  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值