<%@ page language="java" pageEncoding="UTF-8"
contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean"
prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html"
prefix="html"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>注册</title>
<script type="text/javascript" language="javascript" >
<!--
var XMLHttpReq = false;
//创建XMLHttpRequest对象
function createXMLHttpRequest() {
if (window.XMLHttpRequest) { //Mozilla 浏览器
XMLHttpReq = new XMLHttpRequest();
} else {
if (window.ActiveXObject) { // IE浏览器
try {
XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
alert("XMLHttpRequest创建失败!");
}
}
}
}
}
//发送请求函数
function sendRequest(URL) {
createXMLHttpRequest();
XMLHttpReq.open("POST", URL, true);
XMLHttpReq.onreadystatechange = processResponse;//指定响应函数
XMLHttpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
XMLHttpReq.send(null); // 发送请求
}
// 处理返回信息函数
function processResponse() {
if (XMLHttpReq.readyState == 4) { // 判断对象状态
// alert("回调函数");
if (XMLHttpReq.status == 200) { // 信息已经成功返回,开始处理信息
var res = XMLHttpReq.responseText;
chkck.innerHTML = res;
if(res=="工号已存在!")
{
document.getElementById("sbs").disabled="true";
}
if(res=="此工号可用!")
{
document.getElementById("sbs").disabled="";
}
}
}
}
// 工号唯一性验证函数(number)
function userNumberCheck() {
var number = document.getElementById("USER_NUMBER").value;
if(number.length>0)
{
//alert(number);
chkck.style.display = "";
//alert("发送请求");
sendRequest("/vacation_manage/checkUserNumber.do?number=" + number);
}
}
//用户注册验证函数
function regCheck() {
var userNumber = document.getElementById("USER_NUMBER").value;
var username = document.getElementById("USERNAME").value;
var password = document.getElementById("PASSWORD").value;
var rep_password = document.getElementById("REP_PASS").value;
var email = document.getElementById("ee").value;
var yanzhengma = document.getElementById("yzm").value;
if (!userNumber || userNumber.replace(/\s/g, "") == "") {
alert("用户的ID不能为空!");
document.getElementById("USER_NUMBER").focus();
return false;
}
if(userNumber.length>5){
alert("ID不得超过5个字符!");
document.getElementById("USER_NUMBER").focus();
return false;
}
if (!username || username.replace(/\s/g, "") == "") {
alert("用户名不能为空!");
return false;
}
if(username.length>=8){
alert("用户名不得超过4个字!");
document.getElementById("USERNAME").focus();
return false;
}
if (!password || password.replace(/\s/g, "") == "") {
alert("密码不能为空!");
document.getElementById("PASSWORD").focus();
return false;
}
if(password.length<3){
alert("密码不得少于3个字符!");
document.getElementById("PASSWORD").focus();
document.getElementById("PASSWORD").value="";
document.getElementById("REP_PASS").value="";
return false;
}
if (!rep_password || rep_password.replace(/\s/g, "") == "") {
alert("二次密码不能为空!");
document.getElementById("REP_PASS").focus();
return false;
}
if (password != rep_password) {
alert("两次输入的密码不同!");
document.getElementById("PASSWORD").value="";
document.getElementById("REP_PASS").value="";
document.getElementById("PASSWORD").focus();
return false;
}
if(!email||email.replace(/\s/g, "") == ""){
alert("Email不能为空!");
document.getElementById("ee").focus();
return false;
}
if (!(email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)){
alert("请输入合法的Email!");
document.getElementById("ee").focus();
return false;
}
if (!yanzhengma || yanzhengma.replace(/\s/g, "") == "") {
alert("验证码不能为空!");
document.getElementById("yzm").focus();
return false;
}
}
function fush()
{
document.getElementById("yanzm").style.display="none";
}
//-->
</script>
<link rel="stylesheet" href="/vacation_manage/css/common.css">
</head>
<body>
<html:form action="/register" method="post" >
<table align="center" >
<tr>
<td align="left" style="color: blue">
填写注册信息
</td>
</tr>
<tr align="center">
<td>
<table >
<tr>
<td align="right">
工号 :
</td>
</tr>
<tr>
<td align="right">
用户名 :
</td>
</tr>
<tr>
<td align="right">
密码 :
</td>
</tr>
<tr>
<td align="right">
重输入密码 :
</td>
</tr>
<tr>
<td align="right">
Email :
</td>
</tr>
<tr>
<td align="right">
验证码:
</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td align="left">
<html:text property="userNumber" value="" size="15" onfocus="fush()"
styleId="USER_NUMBER" />
<span>不超过5个字符</span>
<span id="chkck" style="display: none ;color: blue">检测中...请稍后</sapn>
</td>
</tr>
<tr>
<td align="left">
<html:text property="username" value="" size="15" styleId="USERNAME"
onfocus="userNumberCheck()" />
<span>不超过5个汉字</span>
</td>
</tr>
<tr>
<td align="left">
<html:password property="password" size="17" value="" styleId="PASSWORD" onfocus="clear()"/>
<span>不少于3个字符</span>
</td>
</tr>
<tr>
<td align="left">
<html:password property="rep_password" size="17" value="" styleId="REP_PASS"/>
</td>
</tr>
<tr>
<td align="left">
<html:text property="email" value="" size="15" styleId="ee" />
</td>
</tr>
<tr>
<td align="left">
<html:text property="yanzhengma" value="" size="15" styleId="yzm" />
<img src="/vacation_manage/page/yanzhengma.jsp" id="CheckCodeimg" title="看不清请点击右边!"/></td>
<td><a href="#" onclick="document.getElementById('CheckCodeimg').src='/vacation_manage/page/yanzhengma.jsp';">看不清?</a></td>
<div id="yanzm" style="color: red" ><html:errors property="yanzhengma"/></div>
</tr>
</table>
</td>
</tr>
<tr align="center">
<td>
<html:submit value="创建用户" onclick="return regCheck()" disabled="false" styleId="sbs"/>
</td>
<td>
<html:reset value="取消" />
</td>
</tr>
</table>
</html:form>
</body>
</html>
/******************************************************
package com.action;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.dao.DbUserDAO;
import com.po.DbUser;
/**
* ajax验证用户的ID是不是存在
*
* @version1.0 2007/10/31
* @author Administrator
*
*/
public class CheckUserNumberActionAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
DbUserDAO dbUserDAO = new DbUserDAO();
String number = request.getParameter("number");
//System.out.println("the id is "+ number);
DbUser user = dbUserDAO.validateUserNumber(number);
if (user != null) {
out.print("工号已存在!");//
out.close();
return null;
} else {
out.print("此工号可用!");
out.close();
return null;
}
}
}
posted on 2007-12-11 17:25
Crying 阅读(549)
评论(0) 编辑 收藏 所属分类:
AJAX