日期:2014-05-20  浏览次数:20839 次

用struts的validator怎么验证密码长度?
请问用struts的validator怎么验证密码长度?
还有我能不能把提示的内容不写在资源文件中,而是直接写在xml中,我用resource="false"好象还是不行....
  <field property="password" depends="required,maxlength">
  <arg0 key="password.require" name="requied" resource="false"/>
  <arg1 key="密码不能超过12位" name="maxlength" resource="false"/>
  <var>
  <var-name>maxlength</var-name>
  <var-value>12</var-value>
  </var>
  </field>


------解决方案--------------------
<arg1 key="${var:maxlength}" name="maxlength" resource="false"/> 
<var> 
<var-name>maxlength</var-name> 
<var-value> 12 </var-value> 
</var>
这样..你看对不对..
------解决方案--------------------
应该form中有个validate方法,在里面进行验证
在struts.xml中的validate设为true

<action input="/rent/searchRentChanged.jsp"
path="/searchRentChanged"
name="SearchRentChangedForm"
scope="request" type="phc.tjtrust.rent.request.action.SearchRentChangedAction"
validate="true">
<forward name="success" path="/rent/searchRentChanged.jsp"/>
<forward name="error" path="/rent/searchRentChanged.jsp"/>
</action>
------解决方案--------------------
<formset>
<form name= "loginForm ">  
<field property= "name " depends= "required ">
<arg0 key= "name "/>
</field>
<field property= "password " depends= "required,minlength,maxlength ">
<arg0 key= "password " resource= "false "/>
<arg1 name= "minlength " key= "${var:minlength} " resource= "false "/>
<arg2 name= "maxlength " key= "${var:maxlength} " resource= "false "/>
<var>
<var-name> minlength </var-name>
<var-value> 0 </var-value>
</var>
<var>
<var-name> maxlength </var-name>
<var-value> 12 </var-value>
</var>
</field>
</form>
</formset>