我正在爲我的應用程序使用Struts 1.2。我有我的表單驗證方法,我正在做一些驗證用戶提供的輸入。下面是由用戶提供的userName
的代碼:如果用戶名是不是由用戶wntered,然後應顯示在UI上述錯誤消息未在UI中顯示Struts錯誤消息
@Override
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
System.out.println("Validating the Form...");
ActionErrors errors = new ActionErrors();
if(userName != null && userName.length() <= 0)
errors.add("userName",new ActionError("Invalid UserName"));
return errors;
}
。以下是我在jsp文件中用於顯示以上錯誤消息的代碼:
<logic:messagesPresent property="userName">
<html:messages id="userName" property="userName">
<bean:write name="userName"/>
</html:messages>
</logic:messagesPresent>
但它沒有顯示任何錯誤消息。
我也試過這種替代,但這也沒有工作:
<logic:messagesPresent property="userName">
<html:errors property="userName" /><html:errors/>
</logic:messagesPresent>
當我嘗試調試代碼,是越來越在form
執行validate
方法和execute
方法不會被觸發,因爲有驗證錯誤。在用戶界面中,不會顯示錯誤消息。請讓我知道如何解決這個問題。
謝謝,它解決了我的問題。 – user182944 2013-05-12 11:55:44