Struts Validation.xml问题

时间:2010-06-28 09:58:29

标签: java struts

我想验证密码长度,指定minlength应该是15,我使用struts validtion.xml来做到这一点,我能够验证必填字段而不是长度,我出错了。代码就像

的validation.xml

 <formset>
     <form name="LoginForm">
      <field property="password" depends="required,minlen">
       <arg key="label.password" position="0"/>    
                 <arg key="${var:minlen}" resource="false" />
           <var>
             <var-name>minlen</var-name>
             <var-value>3</var-value>
           </var>
      </field>
      <field property="userName" depends="required">
       <arg key="label.userName" position="0"/>
      </field>
     </form>
    </formset>

jsp就像

<html:form action="/Login?method=login">
<body>
<table cellspacing="0" cellpadding="0" borde="0" style="width:300px;text-align:left;">
 <tr><td colspan=2><html:errors /></td></tr>
 <tr>
  <th><bean:message key="label.userName"/></th>
  <td><html:text name="LoginForm" property="userName" /></td>
 </tr>
 <tr>
  <th><bean:message key="label.password"/></th>
  <td><html:password name="LoginForm" property="password" /></td>
 </tr>
 <tr>
  <td colspan="2">&nbsp;</td>
 </tr>
 <tr>
  <td colspan="2" align="center"><html:submit styleClass="submit" value="Login" style="width:60px; text-align:center"/></td>
 </tr>
</table>
</body>
</html:form>

请告诉我该怎么做?

1 个答案:

答案 0 :(得分:0)

您的validation.xml应为:

<field property="password" depends="required,minlength">
    <arg0 key="label.password" position="0"/>
    <arg1 name="minlength" key="${var:minlength}" resource="false"/>
    <var>
    <var-name>minlength</var-name>
    <var-value>3</var-value>
</var>
</field>

查看http://struts.apache.org/1.2.4/userGuide/dev_validator.html

中的“标准内置验证”部分