如何判断新输入的注册用户名是否在数据库中存在

wydyl 2009-03-27 04:34:15
<head>


<title>My JSP 'reg.jsp' starting page</title>

<script type="text/javascript">
function regf(){
var name=document.getElementById("regName");//注册名
var pwd=document.getElementById("regPwd");//注册密码
var pwd1=document.getElementById("regPwd1");//重复密码
var sex=document.getElementById("sex");//选择的性别
var head=document.getElementById("head");//选择的头像
if(name.value.length==0){
alert("用户名不能为空!");
return false;
}
if(pwd.value.length==0){
alert("密码不能为空!");
return false;
}if(pwd.value.length>=0&&pwd.value.length<6)
{
alert("密码长度必须大于六位!");
return false;
}
if(pwd1.value.length==0){
alert("必须输入重复密码");
return false;
}
if(pwd1.value!=pwd.value)
{
alert("你输入的密码不相符合!请重新输入");
return false;
}
if(sex.checked(false)){
alert("请选择性别!");
return false;
}
if(sex.value.length==0){
alert("请选择头像!");
return false;
}

return true;
}
function doTest(){


}
</script>
</head>


<body>



%>
<%@ include file="../include/includeTop.jsp" %>
<p>
>><a href="index.jsp" style="color:darkblue; font-size:12px;"/> 论坛首页</a>
</p>
<form name="f1" method="post" action="../Pro/proReg.jsp" onsubmit="return regf()">
<div style="border:1px solid #6699cc;height:150px;">
<table width="950px" style="font-size:12px;margin-top:35px; ">
<tr align="center">
<td>用户名   <input type="text" name="regName" id="regName" value="" style="width:160px;border:1px solid #6699cc"/>
<INPUT TYPE="RESET" NAME="BUTTON" VALUE="是否可用" ONCLICK="doTest()">
</td>
</tr>
<tr align="center">
<td>密  码   <input type="password" name="regPwd" id="regPwd" value="" style="width:160px;border:1px solid #6699cc"/></td>
</tr>
<tr align="center">
<td>重复密码 <input type="password" name="regPwd1" id="regPwd1" value="" style="width:160px;border:1px solid #6699cc"/></td>
</tr>
<tr align="center">
<td>性别 <input type="radio" name="sex" id="sex" value="">男 <input type="radio" name="sex" value="" checked="checked">女</td>
</tr>
<tr align="center">
<td>请选择头像</td>
</tr>
<tr align="center">
<td><img src="../images/head/1.gif"/><input type="radio" value="" name="head" checked="checked">
<img src="../images/head/2.gif"/><input type="radio" value="" name="head">
<img src="../images/head/3.gif"/><input type="radio" value="" name="head">
<img src="../images/head/4.gif"/><input type="radio" value="" name="head">
<img src="../images/head/5.gif"/><input type="radio" value="" name="head">
</td>
</tr>
我有一个问题想问问大家 当我注册用户的时候如何判断注册的用户名是否存在
...全文
1078 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
skyljh 2009-04-08
  • 打赏
  • 举报
回复
严重同意楼上的,我做的第一个ajax小应用就是楼主想要的!
注册页面:
<TR class=tdbg>
<TD width="43%"><B>用户名:</B><BR>不能超过14个字符(7个汉字)</TD>
<TD width="57%"><INPUT type="text" maxLength=14 size=27 name=usercode onblur="viliUser(this.value)" require="true" dataType="Require" msg="
用户名不能为空"> <FONT
color=#ff0000>*</FONT> </TD></TR>
<tr class=tdbg>
<td width="43%" id="mess" style="color:red"></td>
<td width="57%"> </td>
</tr>
js脚本:
<script language="javascript">

function viliUser(usercode){

if(window.XMLHttpRequest){
req = new XMLHttpRequest ;
}else if(window.ActiveXObject){
req = new ActiveXObject("Microsoft.XMLHttp") ;
}

req.onreadystatechange = changMess ;
req.open("GET","viliUsername.jsp?usercode="+usercode,true) ;
req.send(null) ;
}

function changMess() {
if(req.readystate == 4){
if(req.status == 200){

document.getElementById("mess").innerHTML = req.responseText ;
}

}
}
</script>
响应页面:
<!-- 获得用户名 -->
<%
//System.out.println ("aaaaaaaaaa");
String u = request.getParameter("usercode") ;
try {

Operate ope = new Operate();
boolean showFlag = ope.checkRegName(u);

if(u.length()<=14){
if(showFlag){
%>恭喜此用户名可以注册<%
}else{
%>用户名已存在<%
}
}else{
%>用户名超出规定长度<%
}
}
catch (Exception ex) {
ex.printStackTrace();
}

%>
具体的实现方法就是取得数据库链接以后查询表。
flowersove 2009-04-08
  • 打赏
  • 举报
回复
建议用Ajax做判断
Da侠饶命 2009-04-08
  • 打赏
  • 举报
回复
这方法不错呀,嘿嘿,学习了
erlei20082008 2009-04-08
  • 打赏
  • 举报
回复
我这里有个简单的登陆判断程序,用struts2.0做的
nerain 2009-04-08
  • 打赏
  • 举报
回复
我一般也都会用count
wydyl 2009-04-08
  • 打赏
  • 举报
回复
不敢怎样还是谢谢了!
我不是男孩子所以别叫我兄弟
hoojo 2009-03-27
  • 打赏
  • 举报
回复
select count(*) from userInfo where username = 'boy'
如果boy 存在 就会返回 1
否则0
怎么样?
兄弟 试试看
^_*
xuexinsino 2009-03-27
  • 打赏
  • 举报
回复
查数据库呗

81,115

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧