日期:2014-05-20 浏览次数:20864 次
public class LoginAction extends ActionSupport { private String name; private String password; private String rePassword; private String age; private Date date; private String email; public String getName() { return name; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getAge() { return age; } public void setAge(String age) { this.age = age; } public Date getDate() { return date; } public void setDate(Date date) { this.date = date; } @Override public void validate() { if (name.equals("") || name == null) { this.addFieldError("name", "姓名不能为空!"); } else if (!name.matches("[[a-z]|[A-Z]]*")) { this.addFieldError("name", "姓名只能字母!"); } if (!age.matches("\\d+")) { this.addFieldError("age", "年龄必须为数字!"); } else if (Integer.valueOf(age) < 1 || Integer.valueOf(age) > 150) { this.addFieldError("age", "年龄不符合规范!"); } if (password.matches("") || password == null) { this.addFieldError("password", "密码不能为空!"); } else if (!rePassword.matches(password)) { this.addFieldError("rePassword", "两次输入的密码不同!"); } if (!email .matches("^([0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\\w]*[0-9a-zA-Z])*\\.)+[a-zA-Z]{2,9})$")) { this.addFieldError("email", "邮箱必须符合规范!"); } } public String execute() { if (name.equals("123") && password.equals("123") && rePassword.equals(password)) { return SUCCESS; } else { return INPUT; } } public String getRePassword() { return rePassword; } public void setRePassword(String rePassword) { this.rePassword = rePassword; } }