求教,struts2中使用xml配置validator,文本字段只配置stringlength,不配置requirestring,貌似不起作用
1个回答
展开全部
<!DOCTYPE validators PUBLIC
"-//Apache Struts//XWork Validator 1.0.2//EN"
"http://struts.apache.org/dtds/xwork-validator-1.0.2.dtd">
<validators>
<field name="name"><!-- 要对哪个属性进行验证 -->
<field-validator type="requiredstring"><!-- 验证规则 -->
<message>姓名不能为空!</message><!-- 违反规则的提示 -->
</field-validator>
</field>
<field name="age">
<field-validator type="required">
<message>年龄不能为空</message>
</field-validator>
<field-validator type="int">
<param name="min">1</param>
<param name="max">200</param>
<message >年龄必须在${min}和${max}之间</message>
</field-validator>
</field>
</validators>
"-//Apache Struts//XWork Validator 1.0.2//EN"
"http://struts.apache.org/dtds/xwork-validator-1.0.2.dtd">
<validators>
<field name="name"><!-- 要对哪个属性进行验证 -->
<field-validator type="requiredstring"><!-- 验证规则 -->
<message>姓名不能为空!</message><!-- 违反规则的提示 -->
</field-validator>
</field>
<field name="age">
<field-validator type="required">
<message>年龄不能为空</message>
</field-validator>
<field-validator type="int">
<param name="min">1</param>
<param name="max">200</param>
<message >年龄必须在${min}和${max}之间</message>
</field-validator>
</field>
</validators>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询