日期:2014-05-16 浏览次数:20740 次
ajax实现用户名和邮箱的唯一的验证
采用struts2+hibernate+ajax实现user用户注册时用户名和邮箱的唯一验证
index.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>用户注册</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/util.js"></script>
<script type="text/javascript"
src="${pageContext.request.contextPath }/js/reg.js"></script>
</head>
<body>
<div align="center">
<h3>注册页面</h3>
<s:form action="AdminAction_reg" namespace="/csdn" theme="simple">
<table bordercolor="red" width="450px">
<tr>
<td width="100px">用户名:</td>
<td width="200px"><s:textfield name="adminName" id="adminName"></s:textfield>
</td>
<td width="150px"><font color="red"><span id="cname"></span></font></td>
</tr>
<tr>
<td>密码:</td>
<td><s:password name="adminPass" id="adminPass"></s:password>
</td>
<td></td>
</tr>
<tr>
<td>邮箱:</td>
<td><s:textfield name="adminEmail" id="adminEmail"></s:textfield>
</td>
<td><font color="red"><span id="cmail"></span></font></td>
</tr>
<tr align="center">
<td colspan="3"><s:submit value="注册" />
</td>
<td></td>
</tr>
</table>
</s:form>
</div>
</body>
</html>
reg.js(验证)文件的源代码:
window.onload = function() {
var name = $("adminName");
v