2011-12-02 68 views
0

我在我的Action中使用validate(),這裏是我的validate()方法的外觀。Struts2中的重複驗證錯誤

public void validate() { 

    logger.info(".validate() : userName=["+userName+"] & password=["+password+"]"); 

    clearActionErrors(); 

    if(userName==null || userName.length()==0){ 
     addFieldError("userName", "User Name is required."); 
    } 

    if(password==null || password.length()==0){ 
     addFieldError("password", "Password is required."); 
    } 
} 

而在jsp我加入了部分。

錯誤按預期顯示。如何當我刷新頁面,我看到錯誤兩次。此外,如果我繼續刷新它的錯誤消息得到顯示的次數增加1.

不知道這是什麼問題。

我試着調用clearActionErrors();在我的execute()方法中,似乎沒有解決問題。

感謝

+0

additionaly需要你的jsp和struts配置文件的代碼 –

+1

你是否使用spring插件來創建動作實例??? –

+0

我和Umesh在一起;這幾乎總是由於使用Spring和創建單例而不是原型bean。 –

回答

0

如果您正在使用烏爾JSP表顯示窗體,然後確保該表的形式爲標籤的父。如果表格是表單標籤的子元素,則驗證消息不會每次都被清除。將表格標籤作爲表格標籤的子標籤可以解決您的問題。