7.4.2 建立业务控制器
建立一个简单的业务控制器实现类,如代码7.21所示。
代码7.21 AJAX校验示例的业务控制器
package
ch7;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import
java.util.Date;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import
com.opensymphony.xwork2.ActionSupport;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
public
class
Reg_ajax_Action
extends
ActionSupport
{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private String name;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private int age;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private Date birthday;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//属性的getter和setter方法
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public String getName() {
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return name;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public void setName(String name) {
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.name = name;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public int getAge() {
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return age;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public void setAge(int age) {
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.age = age;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public Date getBirthday() {
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return birthday;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public void setBirthday(Date birthday) {
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.birthday = birthday;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
该Action非常简单,只是定义了3个相应的属性。在配置文件中加入如下内容:
<action name="Reg_ajax_Action" class="ch7.Reg_ajax_Action">
<result name="input">/ch7/reg-ajax.jsp</result>
</action>
7.4.3 建立校验规则文件
建立一个Reg_ajax_Action-validation.xml校验规则文件,如代码7.22所示。
代码7.22 AJAX校验示例的校验规则文件
<!
DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"
>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!--
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Add the following DOCTYPE declaration as first line of your XXX-validation.xml file:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
-->
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<
validators
>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<
field
name
="name"
>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<
field-validator
type
="requiredstring"
>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<
message
>
用户名不能为空!
</
message
>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</
field-validator
>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</
field
>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<
field
name
="age"
>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<
field-validator
type
="int"
>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<
param
name
="min"
>
13
</
param
>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<
param
name
="max"
>
19
</
param
>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<
message
>
年龄必须在13至19岁之间
</
message
>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</
field-validator
>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</
field
>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<
field
name
="birthday"
>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!--
定义类型为date
-->
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<
field-validator
type
="date"
>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!--
校验生日有效时间段
-->
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<
param
name
="min"
>
1990-01-01
</
param
>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<
param
name
="max"
>
2006-01-01
</
param
>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<
message
>
生日必须在${min}至${max}之间
</
message
>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</
field-validator
>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</
field
>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</
validators
>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
★ 说明 ★
该校验规则文件也是一个标准的校验规则文件。
7.4.2 建立业务控制器
建立一个简单的业务控制器实现类,如代码7.21所示。
代码7.21 AJAX校验示例的业务控制器
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
该Action非常简单,只是定义了3个相应的属性。在配置文件中加入如下内容:
<action name="Reg_ajax_Action" class="ch7.Reg_ajax_Action">
<result name="input">/ch7/reg-ajax.jsp</result>
</action>
7.4.3 建立校验规则文件
建立一个Reg_ajax_Action-validation.xml校验规则文件,如代码7.22所示。
代码7.22 AJAX校验示例的校验规则文件
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
★ 说明 ★
该校验规则文件也是一个标准的校验规则文件。