2010-07-09 52 views

回答

1

我得到了它,validate方法在ActionSupport類delcared,我們應該重寫它在我們的Action類(首先,我們應該擴大ActionSupport類),如下所示,

public class Login extends ActionSupport { 
//execute method goes here 
//getter/setters goes here 
@Override 
public void validate() { 
super.validate(); 
    System.out.println("User Name " + getUserName()); 
    if(getUserName().length()==0) 
     addFieldError("userName", "User Name Required"); 

    } 

} 

,你也應該定義您在strus.xml動作如下

<action name="DemoLogin" class="com.demo.Login"> 
    <result name="SUCCESS">/LoginSuccess.jsp</result> 
    <result name="ERROR">/LoginError.jsp</result> 
    <result name="input">/Login.jsp</result> 
</action> 

這裏<result name="input">/Login.jsp</result>這個標籤是小鬼bcoz,如果不加這個標籤過濾dispathcer,不會來知道,如果驗證錯誤發生渲染的頁面。