struts2验证框架方法一:
*只有一个文件
*在action所对应的包下面建立****-validation.xml(****是action的类名),如:SaveUserAction-validation.xml
*如果是多个方法的action,则这样写:action类名-方法名-validation.xml
============================如下配置================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<!-- <field name="user.firstname">里的name指的是bean实例的属性,这里是user这个实例的属性-->
<field name="user.firstname">
<field-validator type="requiredstring">
<message>姓不能为空</message>
</field-validator>
</field>
<field name="user.lastname">
<field-validator type="requiredstring">
<message>名不能为空</message>
</field-validator>
</field>
<field name="user.age">
<field-validator type="required">
<message>年龄不能为空</message>
</field-validator>
<field-validator type="int">
<param name="min">1</param>
<param name="max">150</param>
<message>年龄应该在${min}与${max}之间</message>
</field-validator>
</field>
</validators>
原文地址:http://blog.51cto.com/1197822/2155264
时间: 2024-10-11 16:18:43