使用Struts2 spring hibernate框架开发项目---------验证用户名是否可用
使用三大框架开发项目中,当我们注册用户时,往往要求数据库中的用户名是唯一的,所以我们需要在注册时进行用户名验证操作,该操作是如何实现的呢?下面的案例详细介绍此内容。坏帐
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="验证用户名"/>
<s:textfield label="密码" name="user.pass"></s:textfield>
<s:submit value="添加"></s:submit>
</s:form>
</body>
</html>
posted on 2011-05-18 09:29
墙头草 阅读(743)
评论(1) 编辑 收藏