1
FormAction应该为
import org.apache.struts.validator.ValidatorForm;
public class LoginForm extends ValidatorForm{
。。。
去掉validator() 和 reset()方法
}
2
创建validation.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN" " http://jakarta.apache.org/commons/dtds/validator_1_0.dtd ">
<form-validation>
<formset>
<form name="loginForm">
<field property="username" depends="minlength">
<arg0 key="loginForm.userName"/>
<arg1 key="${var:minlength}" name="minlength" resource="false"/>
<var><var-name>minlength</var-name>
<var-value>6</var-value>
</var>
</field>
</form>
</formset>
</form-validation>
3
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>
4
在ApplicationResources.properties 中添加
errors.minlength={0} can not be less than {1} characters.
5
在页面上添加
FormAction应该为
import org.apache.struts.validator.ValidatorForm;
public class LoginForm extends ValidatorForm{
。。。
去掉validator() 和 reset()方法
}
2
创建validation.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN" " http://jakarta.apache.org/commons/dtds/validator_1_0.dtd ">
<form-validation>
<formset>
<form name="loginForm">
<field property="username" depends="minlength">
<arg0 key="loginForm.userName"/>
<arg1 key="${var:minlength}" name="minlength" resource="false"/>
<var><var-name>minlength</var-name>
<var-value>6</var-value>
</var>
</field>
</form>
</formset>
</form-validation>
3
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>
4
在ApplicationResources.properties 中添加
errors.minlength={0} can not be less than {1} characters.
5
在页面上添加
<html:errors property="username"/>
本文转自左正博客园博客,原文链接:http://www.cnblogs.com/soundcode/archive/2010/12/20/1911912.html,如需转载请自行联系原作者