classics-struts注册页面
package com.javaweb.action;import com.opensymphony.xwork2.ActionSupport;import java.util.Calendar;import java.util.Date;import java.util.regex.Pattern;public class RegisterAction extends ActionSupport {private String username;private String password;private String repassword;private int age;private Date birth;private String email;public void setUsername(String username) {this.username = username;}public String getUsername() {return username;}public void setPassword(String password) {this.password = password;}public String getPassword() {return password;}public void setRepassword(String repassword) {this.repassword = repassword;}public String getRepassword() {return repassword;}public void setEmail(String email) {this.email = email;}public String getEmail() {return email;}public void setBirth(Date birth) {this.birth = birth;}public Date getBirth() {return birth;}public void setAge(int age) {this.age = age;}public int getAge() {return age;}public void validate() {if (username == null || "".equals(username)) {this.addFieldError("username", "用户名必须输入");} else if (!Pattern.matches("\\w{6,20}", username.trim())) {this.addFieldError("username","用户名必须是字母和数字,长度6到20位之间");}if (password == null || "".equals(password)) {this.addFieldError("password","密码必须输入");} else if (!Pattern.matches("\\w{6,20}", password.trim())) {this.addFieldError("password","密码必须是字母和数字,长度是6到20位");}if(repassword==null||"".equals(repassword)){this.addFieldError("repassword","确认密码必须输入");}else if (!Pattern.matches("\\w{6,20}",repassword.trim())){this.addFieldError("repassword","确认密码必须是字母和数字,长度在6到20位之间");} if(password!=null&&repassword!=null&&!repassword.equals(password)){this.addFieldError("repassword","确认密码和密码必须相同");}if(age<0||age>120){this.addFieldError("age","请输入有效地年龄范围");}Calendar start =Calendar.getInstance();Calendar end =Calendar.getInstance();start.set(1900, 1,1);end.set(2010,1,1);if(birth!=null&&(birth.after(end.getTime())||birth.before(start.getTime()))){this.addFieldError("age","请输入有效地出生年月");}if(email!=null&&!"".equals(email)&&email!=""&&!Pattern.matches("[a-zA-Z][a-zA-Z0-9._-]*@([a-zA-Z0-9]+\\.)+(com|gov|net|com\\.cn|edu\\.cn)",email)){this.addFieldError("email","请输入正确的Email地址");}}public String execute()throws Exception{return SUCCESS;}}
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%><%@taglib prefix="s" uri="/struts-tags"%><%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 'register2.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">--></head><body><center><h2>注册页面</h2><s:form action="register"><s:textfield name="username" label="用户名"></s:textfield><s:password name="password" label="密码"></s:password><s:password name="repassword" label="确认密码"></s:password><s:textfield name="age" label="年龄"></s:textfield><s:textfield name="birth" label="出生年月"></s:textfield><s:textfield name="email" label="邮件地址"></s:textfield><s:submit value="注册"></s:submit></s:form></center></body></html>
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"><struts><package name="struts2" extends="struts-default"><action name="register" class="com.javaweb.action.RegisterAction"><result name="success">/index.jsp</result><result name="input">/register2.jsp</result></action></package></struts>