struts2+jquery組合驗證注冊用戶是否存在
更新時間:2014年04月30日 11:10:35 作者:
這篇文章主要介紹了使用struts2+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>
重復(fù)密碼:
<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;
}
復(fù)制代碼 代碼如下:
<%@ 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>
重復(fù)密碼:
<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方法
復(fù)制代碼 代碼如下:
/**
* 查找用戶是否存在
*
* @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;
}
您可能感興趣的文章:
- 防止未登錄用戶操作—基于struts2攔截器的簡單實現(xiàn)
- Struts2攔截器 關(guān)于解決登錄的問題
- 詳解Struts2中對未登錄jsp頁面實現(xiàn)攔截功能
- Struts2攔截器登錄驗證實例
- Struts2開發(fā)環(huán)境搭建 附簡單登錄功能實例
- struts2與cookie 實現(xiàn)自動登錄和驗證碼驗證實現(xiàn)代碼
- Java struts2 validate用戶登錄校驗功能實現(xiàn)
- 使用MyEclipse 開發(fā)struts2框架實現(xiàn)登錄功能(結(jié)構(gòu)教程)
- JQuery+Ajax+Struts2+Hibernate框架整合實現(xiàn)完整的登錄注冊
- 基于struts2和hibernate實現(xiàn)登錄和注冊功能
相關(guān)文章
jQuery Easyui Datagrid實現(xiàn)單行的上移下移及保存移動的結(jié)果
這篇文章主要介紹了jQuery Easyui Datagrid實現(xiàn)單行的上移下移及保存移動的結(jié)果,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-08-08jQuery實現(xiàn)動態(tài)加載select下拉列表項功能示例
這篇文章主要介紹了jQuery實現(xiàn)動態(tài)加載select下拉列表項功能,結(jié)合實例形式較為詳細(xì)的分析了jQuery動態(tài)加載select下拉列表項的步驟與相關(guān)操作技巧,需要的朋友可以參考下2018-05-05基于jQuery插件jqzoom實現(xiàn)的圖片放大鏡效果示例
這篇文章主要介紹了基于jQuery插件jqzoom實現(xiàn)的圖片放大鏡效果,結(jié)合實例形式分析了jQuery插件jqzoom的使用方法與相關(guān)注意事項,需要的朋友可以參考下2017-01-01ASP.NET jQuery 實例1(在TextBox里面創(chuàng)建一個默認(rèn)提示)
通常用戶在搜索內(nèi)容時,在文本框輸入內(nèi)容前,文本框都會給出默認(rèn)提示,提示用戶輸入正確的內(nèi)容進(jìn)行搜索2012-01-01