posts - 431,  comments - 344,  trackbacks - 0

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>用&nbsp;户&nbsp;注&nbsp;册</b></font></td>
 </tr>
 <tr>
  <td width="147" height="35" align="right">用&nbsp;户&nbsp;名:</td>
  <td width="368"><input type="text" name="UserName" id="username" maxlength="15" size="13" onblur="checkUsername(this.value);">&nbsp;&nbsp;<font color="#ff0000">*</font>&nbsp;&nbsp;<span id="usernameview"></span></td>
 </tr>
 <tr>
  <td height="35" align="right">密&nbsp;&nbsp;&nbsp;&nbsp;码:</td>
  <td><input type="password" name="Password" id="password1" maxlength="15" size="15" onblur="checkPassword(this.value);">&nbsp;&nbsp;<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);">&nbsp;&nbsp;<font color="#ff0000">*</font>&nbsp;&nbsp;<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);">&nbsp;&nbsp;<font color="#ff0000">*</font><span id="realnameview"></span></td>
 </tr>
 <tr>
  <td height="35" align="right">性&nbsp;&nbsp;&nbsp;&nbsp;别:</td>
  <td><select name="sex" id="sex">
  <option value="m">男</option>
  <option value="w">女</option></select>&nbsp;&nbsp;<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" >&nbsp;&nbsp;<font color="#ff0000">*</font></td>
 </tr>
 <tr>
  <td height="35" align="right">手&nbsp;&nbsp;&nbsp;&nbsp;机:</td>
  <td><input type="text" name="mobile" id="mobile" maxlength="12" size="13">&nbsp;&nbsp;<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();">&nbsp;&nbsp;<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>&nbsp;&nbsp;<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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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 周锐 阅读(1065) 评论(0)  编辑  收藏 所属分类: AjaxHibernateStruts

只有注册用户登录后才能发表评论。


网站导航: