2011-11-27 77 views
2
<form-bean name="RegisterForm" type="com.mysite.form.RegisterForm" /> 

<action path="/register" type="com.mysite.action.RegisterAction" name="RegisterForm" input="/register.jsp" validate="true"> 
       <forward name="success" path="/welcome.jsp" /> 
       <forward name="failure" path="/register.jsp" /> 
      </action> 

RegisterForm的Struts忽略验证方法

public class RegisterForm extends ActionForm{ 
private String name; 

    /** 
    Constructor 
    Set+Get 
    **/ 

    public ActionErrors validate(ActionMapping mapping, ServletRequest request) { 

     ActionErrors errorList = new ActionErrors(); 
     System.out.println("VALIDATING"); 
     return errorList; 
    } 
} 

这是我的所有。出于某种原因,似乎控制流直接跳转到ActionForm的execute方法,因为我甚至无法在控制台中看到VALIDATING消息。有什么我失踪?谢谢!

+0

尝试是ValidatorForm而不是ActionForm来验证你的动作形式,让我知道结果。 – Naved

+0

给定的代码不是真正的代码,因为它不能编译(公共而不是公共)。尝试将@Override注释添加到validate方法中,以确保实际上覆盖了ActionForm的validate方法。另外尝试在ActionErrors中包含错误:您可能会错过控制台中的VALIDATING消息。 –

+0

@JBNizet它是真实的代码,但我编辑它,因为有很多验证,并没有指出把这些放在这里。 methos覆盖父方法。 – TGM

回答

1

您需要使用其他重载的validate()方法,它的HttpServletRequest