posts - 13, comments - 7, trackbacks - 0, articles - 0
          第一步,在struts-config文件里添加valudator插件
          <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
          ??? <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,? /WEB-INF/validation.xml" />
          ? </plug-in>

          在action配置里添加屬性
          ? validate="true"


          第二步,

          在validation.xml文件里添加要驗證的表單字段的信息

          <form-validation>
          ??? <formset>
          ?<form name="logonForm">
          ? <field
          ???? property="ipcode"
          ???? depends="required,minlength">
          ??<arg0 key="LogonForm.ipcode"/>
          ??<arg1 name="minlength" key="${var:minlength}" resource="false"/>
          ????????? <var>
          ?????????? <var-name>minlength</var-name>
          ?????????? <var-value>4</var-value>
          ???????? </var>
          ? </field>
          ? <field
          ???? property="password"
          ???? depends="required,mask">
          ???? <arg0 key="LogonForm.password"/>
          ???? <var>
          ??<var-name>mask</var-name>
          ??<var-value>^[0-9a-zA-Z]*$</var-value>
          ???? </var>
          ? </field>
          ??????? </form>
          ??? </formset>
          </form-validation>


          在資源文件里添加


          validation.test.title=struts validation test
          errors.required={0} is required.<p>
          errors.minlength={0} can not be less than {1} characters.<p>
          errors.maxlength={0} can not be greater than {1} characters.<p>
          errors.invalid={0} is invalid.

          errors.byte={0} must be an byte.
          errors.short={0} must be an short.
          errors.integer={0} must be an integer.
          errors.long={0} must be an long.
          errors.float={0} must be an float.
          errors.double={0} must be an double.

          errors.date={0} is not a date.
          errors.range={0} is not in the range {1} through {2}.
          errors.creditcard={0} is not a valid credit card number.
          errors.email={0} is an invalid e-mail address.<p>

          LogonForm.ipcode=<font color=blue>User name</font>
          LogonForm.password=<font color=blue>User password</font>

          等等你所想要添加的信息

          主站蜘蛛池模板: 伊春市| 宁化县| 英吉沙县| 广南县| 博客| 嘉祥县| 天镇县| 正镶白旗| 清徐县| 乌兰察布市| 吉安市| 明光市| 汉中市| 湘潭县| 霍州市| 昂仁县| 乌兰浩特市| 台江县| 林甸县| 黎平县| 阿鲁科尔沁旗| 秀山| 汉川市| 贡嘎县| 塔城市| 巴彦县| 郓城县| 铜川市| 甘谷县| 沁水县| 柳河县| 武宁县| 资溪县| 高安市| 柘城县| 宜兴市| 屏东县| 大渡口区| 金沙县| 新野县| 淄博市|