使用Struts2 spring hibernate框架開發(fā)項(xiàng)目---------驗(yàn)證用戶名是否可用
使用三大框架開發(fā)項(xiàng)目中,當(dāng)我們注冊(cè)用戶時(shí),往往要求數(shù)據(jù)庫中的用戶名是唯一的,所以我們需要在注冊(cè)時(shí)進(jìn)行用戶名驗(yàn)證操作,該操作是如何實(shí)現(xiàn)的呢?下面的案例詳細(xì)介紹此內(nèi)容。壞帳
Insert.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'inseret.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">淘寶女裝夏裝新款
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript"
src="${pageContext.request.contextPath}/js/jquery-1.6.js"></script>
<script type="text/javascript">
function checkUserName(){
var name=$("#uname").val();
$.ajax({
type:"post",
url:"csdn/user_checkUserName",
data:"user.name="+name,
success:function(data){
if(data.user==null){
$("#checkname").html("<font color='red'>用戶名可用</font>");
}else{
$("#checkname").html("<font color='red'>用戶名不可用</font>");
}
},
error:function(jsonmsg){
},
dataType:"json"
});
}
</script>
</head>
<body>
<h2>
用戶登錄
</h2>
<s:form action="user_insert.action" namespace="/csdn">
<s:textfield label="用戶名" name="user.name" id="uname" ></s:textfield>
<span id="checkname"></span>
<input type="button" onclick="checkUserName()" value="驗(yàn)證用戶名"/>
<s:textfield label="密碼" name="user.pass"></s:textfield>
<s:submit value="添加"></s:submit>
</s:form>
</body>
</html>
posted on 2011-05-18 09:29
墻頭草 閱讀(747)
評(píng)論(1) 編輯 收藏