アプリケーションに Struts 1.2 を使用しています。ユーザーから提供された入力に対していくつかの検証を行っているフォームの検証メソッドがあります。userName
以下は、ユーザーが提供するのコードです。
@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;
}
userName がユーザーによって入力されていない場合、上記のエラー メッセージが UI に表示されます。以下は、上記のエラー メッセージを表示するために 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>
コードをデバッグしようとすると、メソッドvalidate
が実行され、検証エラーがあるためメソッドがトリガーされません。UI では、エラー メッセージは表示されません。これを修正する方法を教えてください。form
execute