0
我在製作註冊表格。如何驗證Struts 1中的密碼字段?
我需要檢查兩個密碼字段是否相同。
<validator name="twofields"
classname="com.mysite.StrutsValidator"
method="validateTwoFields"
msg="errors.twofields"/>
<field property="password"
depends="required,twofields">
<arg position="0" key="typeForm.password.displayname"/>
<var>
<var-name>secondProperty</var-name>
<var-value>password2</var-value>
</var>
</field>
方法
public class StrutsValidator {
public static boolean validateTwoFields(
Object bean,
ValidatorAction va,
Field field,
ActionErrors errors,
HttpServletRequest request,
ServletContext application) {
String value = ValidatorUtils.getValueAsString(
bean,
field.getProperty());
String sProperty2 = field.getVarValue("secondProperty");
String value2 = ValidatorUtils.getValueAsString(
bean,
sProperty2);
if (!GenericValidator.isBlankOrNull(value)) {
try {
if (!value.equals(value2)) {
errors.add(field.getKey(),
Resources.getActionError(
application,
request,
va,
field));
return false;
}
}
catch (Exception e) {
errors.add(field.getKey(),
Resources.getActionError( //This line is giving an error.
application,
request,
va,
field));
return false;
}
}
return true;
}
}
我嘗試這樣做,但它給了一個錯誤。方法getActionError(ServletContext, HttpServletRequest, ValidatorAction, Field)
未定義類型資源。