当前位置: 编程技术>WEB前端
struts2+jquery组合验证注册用户是否存在
来源: 互联网 发布时间:2014-08-25
本文导语: 注册界面 register.jsp 代码如下: 注册界面 function findByName() { $.ajax( { url : 'login!findByName', data : { name : $("#name").val() }, type : 'post', dataType : 'text', success : function(data) { if ('exist' === data) { $('#nametip').text('存在该用户'); } else { $('#name...
注册界面 register.jsp
注册界面
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("异常!");
}
});
}
用户注册
用户名:
密 码:
重复密码:
action方法
/**
* 查找用户是否存在
*
* @return
* @throws IOException
*/
public String findByName() throws IOException {
List listPerson = ms.findByName(name);
String findByNameTip;
if (listPerson.size() > 0) {
findByNameTip = "exist"; // 存在用户
} else {
findByNameTip = "noexist"; // 不存在用户
}
ServletActionContext.getResponse().getWriter().print(findByNameTip);
return null;
}
代码如下:
注册界面
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("异常!");
}
});
}
用户注册
用户名:
密 码:
重复密码:
action方法
代码如下:
/**
* 查找用户是否存在
*
* @return
* @throws IOException
*/
public String findByName() throws IOException {
List listPerson = ms.findByName(name);
String findByNameTip;
if (listPerson.size() > 0) {
findByNameTip = "exist"; // 存在用户
} else {
findByNameTip = "noexist"; // 不存在用户
}
ServletActionContext.getResponse().getWriter().print(findByNameTip);
return null;
}