运行结果:
运行结果:注册成功
/struts2_0200_validation/src/com/b510/register/action/RegistAction.java
1 package com.b510.register.action;
2
3 import com.opensymphony.xwork2.ActionSupport;
4
5 import java.util.Date;
6
7 /**
8 * 注册信息Action
9 *
10 * @author Hongten
11 *
12 */
13 public class RegistAction extends ActionSupport {
14 private static final long serialVersionUID = 1L;
15
16 /**
17 * 用户名
18 */
19 private String name;
20 /**
21 * 密码
22 */
23 private String password;
24 /**
25 * 确认密码
26 */
27 private String repassword;
28 /**
29 * 年龄
30 */
31 private int age;
32 /**
33 * 工资
34 */
35 private double salary;
36 /**
37 * 生日
38 */
39 private Date birthday;
40 /**
41 * 邮箱
42 */
43 private String email;
44 /**
45 * 个人主页
46 */
47 private String personPage;
48
49 public int getAge() {
50 return age;
51 }
52
53 public Date getBirthday() {
54 return birthday;
55 }
56
57 public String getEmail() {
58 return email;
59 }
60
61 public String getName() {
62 return name;
63 }
64
65 public String getPassword() {
66 return password;
67 }
68
69 public String getPersonPage() {
70 return personPage;
71 }
72
73 public String getRepassword() {
74 return repassword;
75 }
76
77 public double getSalary() {
78 return salary;
79 }
80
81 public void setAge(int age) {
82 this.age = age;
84
85 public void setBirthday(Date birthday) {
86 this.birthday = birthday;
87 }
88
89 public void setEmail(String email) {
90 this.email = email;
91 }
92
93 public void setName(String name) {
94 this.name = name;
95 }
96
97 public void setPassword(String password) {
98 this.password = password;
99 }
100
101 public void setPersonPage(String personPage) {
102 this.personPage = personPage;
103 }
104
105 public void setRepassword(String repassword) {
106 this.repassword = repassword;
107 }
108
109 public void setSalary(double salary) {
110 this.salary = salary;
111 }
112
113 }
/struts2_0200_validation/src/com/b510/register/action/RegistAction-validation.xml
1 < xml version="1.0" encoding="GBK" >
2
3 4 "-//OpenSymphony Group//XWork Validator 1.0.3//EN"
5 "http://www.opensymphony.com/xwork/xwork-validator-1.0.3.dtd">
6
7
8
9
10
11
12 true
13
14
15
16
17
18
19 ,且长度必须在4到20之间
20
21
22
23
24
25
26 true
27
28
29
30
31
32
33 ,且长度必须在4到25之间
34
35
36
37
38
39
40 true
41
42
43
44
45
46
47
48
49
50
51
52 1
53 120
54
55
56
57
58
59
60 2000.0
61 10000.0
62
63
64
6