首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

struts2 alidate印证

2012-08-24 
struts2 alidate验证---------------------------------------------------validate验证 第一步 \src\com\

struts2 alidate验证

---------------------------------------------------
validate验证 第一步 \src\com\test\bean\User-user-validation.xml 必须写在相应的javaBean下
---------------------------------------------------
<?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="firstname">
??<field-validator type="requiredstring">
???<message>required first name</message>
??</field-validator>
?</field>

?<field name="lastname">
??<field-validator type="requiredstring">
???<message>required last name</message>
??</field-validator>
?</field>

?<field name="age">
??<field-validator type="required">
???<message>required age</message>
??</field-validator>
??<field-validator type="int">
???<param name="min">1</param>
???<param name="max">150</param>
???<message>age should be between ${min} and ${max}</message>
??</field-validator>
?</field>

</validators>
---------------------------------------------------
validate验证 第二步 src\com\test\action\user\SaveUserAction-validation.xml 写在相应的action下
??????????????????? src\com\test\action\user\UpdateUserAction-validation.xml?? 写在相应的action下
---------------------------------------------------
SaveUserAction-validation.xml,UpdateUserAction-validation.xml
<message>user's </message> 加一个前缀 比如:返回错误信息:错误 那么加了这个前缀结果:user's 错误
<?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">
??<field-validator type="visitor">
???<param name="context">user</param>
???<param name="appendPrefix">true</param>
???<message>user's </message>
??</field-validator>
?</field>
</validators>

?

?

热点排行