日期:2014-05-19 浏览次数:20666 次
<script type="text/javascript">
var xmlHttp;
var result = false;
function checkuid(){
var username = document.all.username.value;
if(username.length<3){
document.all.usernameMsg.innerHTML="<font color='red'>用户名太短,请重新输入!</font>";
return false;
}else{
document.all.usernameMsg.innerHTML="<font color='red'>用户名检测中...</font>";
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
var uri = "user!CheckUser.action?username="+username;
xmlHttp.open("post",uri,true);
xmlHttp.onreadystatechange = function(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
var flag = xmlHttp.responseText;
if(flag=="true"){
document.all.usernameMsg.innerHTML="<font color='red'>该用户名已被使用,请您重新选择用户名!</font>";
result = false;
}else{
document.all.usernameMsg.innerHTML="<font color='red'>恭喜您,该用户名可用!</font>";
result = true ;
}
}
}
}
xmlHttp.send(null);
}
}
</script>
public void CheckUser() {
PrintWriter pw = null;
System.out.println("username=" + username);
list = userService.query("from User where username='" + username + "'");
System.out.println(list);
System.out.println("aadasd");
if (list != null) {
pw.write("true");
} else {
pw.write("false");
}
pw.flush();
pw.close();
}
PrintWriter pw = null;
PrintWriter pw = ServletActionContext.getResponse.getWriter();