這個涉及到struts 1中的ActionMessages使用方法。
在action中
代碼如下:
ActionMessages messages = new ActionMessages();
request.setAttribute(DefaultValue.REQUEST_NOTICE_MESSAGE, messages);
messages.add("
user.username", new ActionMessage(
"user already exist", false));
messages.add("
user.email", new ActionMessage("email already exist",
false));
在JSP頁面中,代碼如下:
<logic:notEmpty name="<%=DefaultValue.REQUEST_NOTICE_MESSAGE%>">
<html:messages id="msg"
name="<%=DefaultValue.REQUEST_NOTICE_MESSAGE%>" property="user.exist">
<bean:write name="msg" />
</html:messages>
</logic:notEmpty>
上面的這種方法,就可以顯示并輸出所有的你放到ActionMessages里面的消息。
如果想在特定的地方輸出你定義的消息,可以用
<tr>
<td>
username
</td>
<td>
<input type="text" name="username" value="zhangyi">
</td>
<td>
<html:messages id="msg"
name="<%=DefaultValue.REQUEST_NOTICE_MESSAGE%>"
property="user.username">
<bean:write name="msg" />
</html:messages>
</td>
</tr>
指定了property就可以取道你想取得的消息。這個屬性,就是上面的在action中指定的屬性。
效果如圖:
|----------------------------------------------------------------------------------------|
版權聲明 版權所有 @zhyiwww
引用請注明來源 http://m.tkk7.com/zhyiwww
|----------------------------------------------------------------------------------------|
posted on 2009-11-23 17:59
zhyiwww 閱讀(645)
評論(0) 編輯 收藏 所屬分類:
j2ee