struts 为action配置xml校验文件范本

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.3//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.3.dtd"> 
<validators>
    <field name="username">
        <field-validator type="requiredstring">
            <param name="trim">true</param>
            <message>用户名不能为空!</message>
        </field-validator>
    </field>
    <field >
        <field-validator type="requiredstring">
            <message>手机号不能为空!</message>
        </field-validator>
        <field-validator type="regex">
    <param name="expression"><![CDATA[^1[358]\d{9}$]]></param>
    <message>手机号格式不正确!</message>
</field-validator>
    </field >

</validators>

校验器在default.xml文件中

action必须要继承ActionSupport类

命名规范:actionCalssname-validation.xml(对所有方法进行校验)

actionClassname-actionname-validation.xml(对指定方法校验)采用占位符样例:DemoAction-login_add-validation.xml

你可能感兴趣的:(xml,struts,web开发,struts2.0)