日期:2014-05-16 浏览次数:20367 次
public String checkusername() {
// 获取response对象
response = ServletActionContext.getResponse();
request = ServletActionContext.getRequest();
PrintWriter out=null;
// 获取输出对象
try {
out= response.getWriter();
System.out.println(username);
User us =new User();
user=userService.login(username);
if(user!=null){
System.out.println(user);
request.removeAttribute("user");
out.print(true);
}else {
System.out.println("yes");
out.print(false);
}
} catch (IOException e) {
e.printStackTrace();
}finally {
out.flush();
out.close();
}
return null;
}
<script type="text/javascript">
function retu() {
history.back();
}
function checkname(ouser) {
var username = ouser.value;
if(!username) {
alert("用户名不能为空");
ouser.focus();
return;
}
//发送请求到服务器,判断用户名是否存在
//Ajax是实现。
xhr = getxhr();
var url = "crm/user_checkusername?username="+ encodeURIComponent(username) + "&t=" + (new Date()).getTime();
xhr.onreadystatechange = backcall;
xhr.open("GET",url,true);
xhr.send(null);
}
function getxhr() {
if(window.XMLHttpRequest) {
return new XMLHttpRequest();
}else {
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
function backcall() {
if(xhr.readyState == 4 &&
xhr.status ==200 ) {
var b=xhr.responseText;
//去掉首尾空格
b=b.replace(/(^\s*)|(\s*$)/g,"");
if(b=="true"){
alert("用户名已存在!");
}else {
alert("用户名可以使用!");
}
}
}
</script>
<form action="user_addUser" method="post" >
<!--隐藏域-->
<input type="hidden" name="user.delState" value="1" />
<table border="1" align="center">
<tr>
<td>用户名</td>
<td><input name="user.username" type="text" onblur="checkname(this);"/><span style="color: red">*</span></td>
<td>姓名</td>
<td><input name="user.name" type="text"/><span style="color: red">*</span></td>
</tr>
<tr>
java
Hibernate:
select
user0_.id as id1_,
user0_.USERNAME as USERNAME1_,
user0_.PASSWORD as PASSWORD1_,
user0_.NAME as NAME1_,
user0_.TELEPHONE as TELEPHONE1_,