<html:messages>
Action 中 :
ActionMessages message = new ActionMessages();
message.add(" 消息句柄 ",new ActionMessage(" 资源文件中 Key 值 ",String 类型描述信息 ));
this.addMessages(request,message);
return ActionForward;
JSP 页面中 :
<html:messages id=" 指定使用消息的标识 " property=" 消息句柄 " message="true|false">
<bean:write name=" 以上所指 ID 标识 "/>
</html:messages>
例如:
Action方法中:
saveMessage(request,"页面要显示的消息");
Action的调用的方法,可以写真Action实现类的父类 BaseDispatchAction 中:
public ActionMessages saveMessage(HttpServletRequest request, String key) {
ActionMessages messages = new ActionMessages();
return saveMessage(messages, request, key);
}
protected ActionMessages saveMessage(ActionMessages messages,
HttpServletRequest request, String key) {
messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(key));
saveMessages(request, messages);
return messages;
}
页面:
<html:messages id="msg" message="true"><bean:write name="msg"/></html:messages>
<html:errors>
Action 中 :
ActionMessages message = new ActionMessages();
message.add(" 消息句柄 ",new ActionMessage(" 资源文件中 Key 值 ",String 类型描述信息 ));
this.saveErrors(request,message);
return ActionForward;
JSP 页面中 :
<html:errors property=" 消息句柄 "/>
如果Action中这样设定(false),页面的提示信息将不从资源文件里读取:
ActionMessages message = new ActionMessages();
message.add("消息句柄",new ActionMessage("String类型描述信息));",false));
this.saveErrors(request,message);
return ActionForward;
JSP页面:
<html:errors/>或<html:errors property="消息句柄"/>