码迷,mamicode.com
首页 > 其他好文 > 详细

struts2.3.20中action中的validate校验

时间:2015-02-13 11:51:31      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:struts2.3.20


public class RegisterAction extends ActionSupport

{


private String username;

private String password;

private String repassword;

private int age;

private Date birthday;

private Date graduation;

public String getUsername()

{

return username;

}

public void setUsername(String username)

{

this.username = username;

}

public String getPassword()

{

return password;

}

public void setPassword(String password)

{

this.password = password;

}

public String getRepassword()

{

return repassword;

}

public void setRepassword(String repassword)

{

this.repassword = repassword;

}

public int getAge()

{

return age;

}

public void setAge(int age)

{

this.age = age;

}

public Date getBirthday()

{

return birthday;

}

public void setBirthday(Date birthday)

{

this.birthday = birthday;

}

public Date getGraduation()

{

return graduation;

}

public void setGraduation(Date graduation)

{

this.graduation = graduation;

}

//execute(),只要校验方法有任何一个错误都不会去执行此方法

@Override

public String execute() throws Exception

{

return SUCCESS;

}

//验证方法,重写validate()

/*public void validate()

{

//此处验证用户输入的信息,需要注意的是,此处只处理错误的情况,所以表达式都应该是判断错误的情况下做如何处理

if(username == null || username.length()<6 || username.length()>12)

{

this.addActionError("用户名不合法");

this.addFieldError(username, "您的用户名不合法");

}

if(password == null || password.length()<6 || password.length()>10)

{

this.addActionError("密码不合法");

}

else if(repassword == null || repassword.length()<6 ||repassword.length()>10)

{

this.addActionError("确认密码不合法");

}

else if (!repassword.equals(password))

{

this.addActionError("2次输入密码不同");

}

if(age<18)

{

this.addActionError("您的年龄未满18岁");

}

if(birthday != null && graduation != null)

{

Calendar c1 = Calendar.getInstance();

c1.setTime(birthday);

Calendar c2 = Calendar.getInstance();

c2.setTime(graduation);

if(!c1.before(c2))

{

this.addActionError("您出生在您毕业之后");

}

}

else if(birthday == null)

{

this.addActionError("您的出生日期为空");

}

if (graduation == null)

{

this.addActionError("您的毕业日期为空");

}

}

*/

}


struts2.3.20中action中的validate校验

标签:struts2.3.20

原文地址:http://ssheyy.blog.51cto.com/7252201/1614183

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!