2010.11.08———struts2 validation 简单用法
2010.11.08———struts2 validation 简单用法
1、针对每一个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="gcxx2.GCBM"> <field-validator type="requiredstring"> <message>项目名称不能为空!</message> </field-validator> </field> <field name="gcxx2.HTJG"> <field-validator type="regex"> <param name="expression">![CDATA[/^$[-]?\d+(\.\d+)?/]]</param> <message>合同价格必须为数字!</message> </field-validator> </field> </validators>
<action name="add_dt" method="add_dt"><result name="input" >domain/gongchengxiangmuguanli/gongchengxiangmuguanli_add_dt.jsp</result><result type="redirectAction"><param name="actionName">initGongCheng.action</param><param name="gcbm">${GCBM}</param><param name="flat">${sign}</param></result></action><result name="input" >domain/gongchengxiangmuguanli/gongchengxiangmuguanli_add_dt.jsp</result>即验证没通过返回到那个页面 我们一般选择返回本页面
@SkipValidation public String delete_dt(){....}
<div align="center"><font color="red"><s:fielderror/></font></div>