package sanglp;

 import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.validator.annotations.DateRangeFieldValidator;
import com.opensymphony.xwork2.validator.annotations.IntRangeFieldValidator;
import com.opensymphony.xwork2.validator.annotations.RegexFieldValidator;
import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator; import java.util.Date; /**
* Created by Administrator on 2016/10/11.
*/
public class RegistAction extends ActionSupport{
private String name;
private String pass;
private int age;
private Date birth; public String getName() {
return name;
} public String getPass() {
return pass;
} public int getAge() {
return age;
} public Date getBirth() {
return birth;
} @RequiredStringValidator(key = "name.required",message = "用户名必须填写")
@RegexFieldValidator(regexExpression = "\\w{4,25}",key = "name.regex" ,message = "用户名必须是4到25位数字或字母")
public void setName(String name) {
this.name = name;
} @RequiredStringValidator(key = "pass.required",message = "密码不能为空")
@RegexFieldValidator(regexExpression = "\\w{4,25}",key = "pass.regex",message = "密码必须是4到25位的数字或字母")
public void setPass(String pass) {
this.pass = pass;
} @IntRangeFieldValidator(message = "",key = "age.range" ,max = "150",min = "1")
public void setAge(int age) {
this.age = age;
} @DateRangeFieldValidator(message = "",key = "birth.range",min="1900/01/01",max = "2050/01/21")
public void setBirth(Date birth) {
this.birth = birth;
}
public void validate(){
System.out.println("进去validate方法进行校验"+name);
if(!name.contains("crazyit")){
addFieldError("user","您的用户名必须包含crazyit");
}
}
}

为了在input视图对应的JSP页面输出错误提示,应该在页面增加

<s:fielderror/>

最新文章

  1. [翻译]理解Swift中的Optional
  2. Swift语言之命令模式(Command Pattern)实现
  3. LeetCode 135 Candy(贪心算法)
  4. ecshop 配送方式支持&quot;货到付款&quot;
  5. 报错:HTTP Status 404 - There is no Action mapped for namespace [/] and action name [product-save] associated with context path [/20161101-struts2-2].
  6. 新手留言薄asp.net MVC 学习(适合新手学习)
  7. 如何参与linux 内核开发
  8. IO流03_流的分类和概述
  9. 一个CLI的 的例子
  10. ubuntu安装使用kdevelop
  11. php-fpm:fastcgi_finish_request()
  12. 【ArcGIS 10.2新特性】ArcGIS 10.2 for Server新特性
  13. nginx配置文件作用介绍
  14. JS中数组的迭代方法和归并方法
  15. Excel生成guid、uuid
  16. 浏览器中直接是使用react系列包开发,非打包方式。
  17. BZOJ_2049_[Sdoi2008]Cave 洞穴勘测_LCT
  18. nginx预防常见攻击
  19. Django项目及应用的创建
  20. Codeforces Round #534 (Div. 2)D. Game with modulo-1104-D(交互+二分+构造)

热门文章

  1. windows下制作linux U盘启动盘或者安装优盘(转)
  2. KEIL MDK STM32如何建立工程
  3. Java 工程转 C#
  4. Eliot
  5. Markdown learning
  6. 带权图的最短路径算法(Dijkstra)实现
  7. 2016-2017 CT S03E07: Codeforces Trainings Season 3 Episode 7 - HackerEarth Problems Compilation
  8. NOIP2015子串[序列DP]
  9. sturct2类型转化
  10. https证书提供商