HTML代碼
<html>
<head>
<title>用戶注冊</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
td {
font-size:12px;
color:#000033;
}
span {
font-size:12px;
color:#FF0000;
text-align:center;
height:20px;
vertical-align:bottom;
}
input {
border:0px;
border-bottom:1px #666666 dotted;
color:#3399FF;
}
</style>
<script language="JavaScript">
var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject){
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
if (xmlHttp.overrideMimeType) {
xmlHttp.overrideMimeType('text/xml');
}
}
if (!xmlHttp) {
window.alert("Could not create XMLHttpRequest.");
return false;
}
}
function checkUsername(obj){
createXMLHttpRequest();
document.getElementById("usernameview").innerHTML="";
var url="login.do?method=checkUserName&&UserName="+obj;
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function handleStateChange(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
document.getElementById("usernameview").innerHTML=xmlHttp.responseText;
}
}
}
function checkPassword(obj){
document.getElementById("pwdview").innerHTML="";
if(obj.length<6){
document.getElementById("pwdview").innerHTML="密碼長度不能小于六位!";
}
else{
document.getElementById("pwdview").innerHTML="√";
}
}
function checkPassword2(obj){
var pwd1=document.getElementById("password1").value;
document.getElementById("usernameview").innerHTML="";
if(obj!=pwd1||obj==null)
{
document.getElementById("pwd2view").innerHTML="兩次輸入的密碼不一致!";
}else{
document.getElementById("pwd2view").innerHTML="√";
}
}
function checkRealName(obj){
if(obj==null){
document.getElementById("realnameview").innerHTML="真實姓名不能為空!";
}else{
document.getElementById("realnameview").innerHTML="√";
}
}
</script>
</head>
<body>
<form name="RegistForm">
<table height="328" align="center" cellpadding="0" cellspacing="0" style="border:2px #666666 solid; ">
<tr>
<td colspan="2" height="30" bgcolor="#666666" align="center" style="border-bottom:1px #666666 solid;"><font color="#FFFFFF"><b>用 戶 注 冊</b></font></td>
</tr>
<tr>
<td width="147" height="35" align="right">用 戶 名:</td>
<td width="368"><input type="text" name="UserName" id="username" maxlength="15" size="13" onblur="checkUsername(this.value);"> <font color="#ff0000">*</font> <span id="usernameview"></span></td>
</tr>
<tr>
<td height="35" align="right">密 碼:</td>
<td><input type="password" name="Password" id="password1" maxlength="15" size="15" onblur="checkPassword(this.value);"> <font color="#ff0000">*</font><span id="pwdview"></span></td>
</tr>
<tr>
<td height="35" align="right">密碼校驗:</td>
<td><input type="password" name="Password2" id="password2" maxlength="15" size="15" onblur="checkPassword2(this.value);"> <font color="#ff0000">*</font> <span id="pwd2view"></span></td>
</tr>
<tr>
<td height="35" align="right">真實姓名:</td>
<td><input type="text" name="realname" id="realname" size="10" maxlength="10" onblur="checkRealName(this.value);"> <font color="#ff0000">*</font><span id="realnameview"></span></td>
</tr>
<tr>
<td height="35" align="right">性 別:</td>
<td><select name="sex" id="sex">
<option value="m">男</option>
<option value="w">女</option></select> <font color="#ff0000">*</font></td>
</tr>
<tr>
<td height="35" align="right">聯系電話:</td>
<td><input type="text" name="tel" id="tel" maxlength="12" size="13" > <font color="#ff0000">*</font></td>
</tr>
<tr>
<td height="35" align="right">手 機:</td>
<td><input type="text" name="mobile" id="mobile" maxlength="12" size="13"> <font color="#ff0000">*</font></td>
</tr>
<tr>
<td height="35" align="right">E - mail:</td>
<td><input type="text" name="email" id="email" size="25" onChange="checkEmail();"> <font color="#ff0000">*</font></td>
</tr>
<tr>
<td height="86" align="right">個人簡介:</td>
<td><textarea cols="30" rows="4" class="text" name="memo" style="overflow:auto; border:1px #666666 solid; color:#3399FF;"></textarea> <font color="#ff0000">*</font></td>
</tr>
<tr>
<td height="10" colspan="2"></td>
</tr>
<tr>
<td height="30" colspan="2" align="center" style="border-top:1px #666666 solid; "><input onClick="javascript:addUser();" style="background-color:#666666; color:#FFFFFF; border:0; text-align:center; width:60px;" type="button" name="add" value="A D D"> <input style="background-color:#666666; color:#FFFFFF; border:0; width:60px;" type="reset" name="reset" value="R E T"></td>
</tr>
</table>
</form>
</body>
</html>
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.rain.struts.action;
import Java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.apache.struts.validator.DynaValidatorForm;
import com.rain.bean.Regist;
/**
* MyEclipse Struts
* Creation date: 09-12-2006
*
* XDoclet definition:
* @struts.action parameter="method" validate="true"
*/
public class LoginAction extends DispatchAction {
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward checkUserName(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
Regist regist=new Regist();
DynaValidatorForm loginForm = (DynaValidatorForm)form;
String username=loginForm.getString("UserName");
System.out.println(username);
boolean flag=regist.findByName(username);
System.out.println("test");
if(flag)
{
try {
response.getWriter().write("sorry!");
} catch (IOException e) {
// TODO 自動生成 catch 塊
e.printStackTrace();
}
}else
{
try {
response.getWriter().write("luck!");
} catch (IOException e) {
// TODO 自動生成 catch 塊
e.printStackTrace();
}
}
return null;
}
}
posted on 2006-09-13 09:29
周銳 閱讀(1077)
評論(0) 編輯 收藏 所屬分類:
Ajax 、
Hibernate 、
Struts