DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> jQuery入門知識 >> JQuery特效代碼 >> struts2+jquery組合驗證注冊用戶是否存在
struts2+jquery組合驗證注冊用戶是否存在
編輯:JQuery特效代碼     
注冊界面 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;
}
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved