struts2+jquery组合验证注册用户是否存在

时间:2014-04-30    点击:84   
注册界面 register.jsp
复制代码 代码如下:

<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<html>
<head>
<title>注册界面</title>
<script type="text/javascript" src="js/jquery-1.6.js">
</script>
<script type="text/javascript">
function findByName() {
$.ajax( {
url : 'login!findByName',
data : {
name : $("#name").val()
},
type : 'post',
dataType : 'text',
success : function(data) {
if ('exist' === data) {
$('#nametip').text('存在该用户');
} else {
$('#nametip').text('不存在该用户');
}
},
error : function() {
alert("异常!");
}
});
}
</script>
</head>
<body>
<form action="login!register" method="post">
<table align="center">
<caption>
<h3>
用户注册
</h3>
</caption>
<tr>
<td>
用户名:
<input type="text" id="name" name="name" onblur="findByName()" />
</td>
<td>
<div id="nametip">

</div>
</td>
</tr>

<tr>
<td>
密 码:
<input type="text" name="password" />
</td>
</tr>
<tr>
<td>
重复密码:
<input type="text" name="password2" />
</td>
</tr>
<tr align="center">
<td colspan="2">
<input type="submit" value="注册" />
<input type="reset" value="重填" />
</td>
</tr>
</table>
</form>
</body>
</html>

action方法
复制代码 代码如下:

/**
* 查找用户是否存在
*
* @return
* @throws IOException
*/
public String findByName() throws IOException {
List<Person> listPerson = ms.findByName(name);
String findByNameTip;
if (listPerson.size() > 0) {
findByNameTip = "exist"; // 存在用户
} else {
findByNameTip = "noexist"; // 不存在用户
}
ServletActionContext.getResponse().getWriter().print(findByNameTip);
return null;
}
jquery map方法使用示例
js通过更改按钮的显示样式实现按钮的滑动效果
js Dialog 去掉右上角的X关闭功能
Jquery实现Div上下移动示例
js函数定时器实现定时读取系统实时连接数
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved