struts2-{Action}-validation.xml

1.{Action}-validation.xml与Class建立在同一个包下面;

 

2.struts.xml可以加入如下代码:

<action name="validation" class="com.validation.test.Validation">
   <result name="success">/output.jsp</result>
   <result name="input">/input.jsp</result>
  </action>

3.input.jsp

<s:fielderror cssStyle="color:red"/>
<s:form action="validation" theme="simple">
 输入字符串<s:textfield name="requireString"/>
 <s:submit/>
</s:form>

注:com.opensymphony.xwork2/Action:

<result name="input">/input.jsp</result>

INPUT

ERROE

LOGIN

NONE

SUCCESS...

com.opensymphony.xwork2.validator.validators/default.xml

<field name="requireString">
        <field-validator type="requiredstring">
            <message>字符串不能为空!</message>
        </field-validator>
    </field>


<validators>//下面这些方法满足大多数开发要求
    <validator name="required" class="com.opensymphony.xwork2.validator.validators.RequiredFieldValidator"/>
    <validator name="requiredstring" class="com.opensymphony.xwork2.validator.validators.RequiredStringValidator"/>
    <validator name="int" class="com.opensymphony.xwork2.validator.validators.IntRangeFieldValidator"/>
    <validator name="long" class="com.opensymphony.xwork2.validator.validators.LongRangeFieldValidator"/>
    <validator name="short" class="com.opensymphony.xwork2.validator.validators.ShortRangeFieldValidator"/>
    <validator name="double" class="com.opensymphony.xwork2.validator.validators.DoubleRangeFieldValidator"/>
    <validator name="date" class="com.opensymphony.xwork2.validator.validators.DateRangeFieldValidator"/>
    <validator name="expression" class="com.opensymphony.xwork2.validator.validators.ExpressionValidator"/>
    <validator name="fieldexpression" class="com.opensymphony.xwork2.validator.validators.FieldExpressionValidator"/>
    <validator name="email" class="com.opensymphony.xwork2.validator.validators.EmailValidator"/>
    <validator name="url" class="com.opensymphony.xwork2.validator.validators.URLValidator"/>
    <validator name="visitor" class="com.opensymphony.xwork2.validator.validators.VisitorFieldValidator"/>
    <validator name="conversion" class="com.opensymphony.xwork2.validator.validators.ConversionErrorFieldValidator"/>
    <validator name="stringlength" class="com.opensymphony.xwork2.validator.validators.StringLengthFieldValidator"/>
    <validator name="regex" class="com.opensymphony.xwork2.validator.validators.RegexFieldValidator"/>
    <validator name="conditionalvisitor" class="com.opensymphony.xwork2.validator.validators.ConditionalVisitorFieldValidator"/>
</validators>

 

你可能感兴趣的:(xml,jsp,struts)