如何实现struts的validator框架?
手动:
????public class myForm extends ActionForm?
????{
?????public ActionErrors validate()
?????{
actionErrors.add(ActionErrors.GLOBAL_MESSAGE,new ActionMessage(”properties中的键名”));
?????}
????}?
????struts-config.xml中修改action的标签validate=true
?????input=”错误页面”
????如果validate方法中的ActionErrors不为空且size>0时
????会回到input页面。
???自动
????public class myForm extends ValidateForm?
????{
?????不能覆盖validate方法。
?????//public void validate()
?????//{
??
?????//}
????}?
????在struts-config.xml文件中加入插件
????? <plug-in className=”org.apache.struts.validator.ValidatorPlugIn”>
????? ????<set-property property=”pathnames” value=”/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml” />
???? ??</plug-in>
??修改validation.xml中的内容
???errors.required={0} is required.
???errors.minlength={0} can not be less than {1} characters.
???<formset>
????<form name=”loginForm”>
?????<field property=”userName” depends=”required”>
??????<arg0 key=”userName” />
?????</field>
?????<field property=”pwd” depends=”required,minlength”>
??????<arg0 key=”pwd” />
??????<arg1 key=”${var:minlength}” resource=”false”/>
??????<var>
???????<var-name>minlength</var-name>
???????<var-value>6</var-value>
??????</var>
?????</field>
????</form>
???</formset>
???struts-config.xml中修改action的标签validate=true
?????input=”/错误页面”