Struts 1.2.2 新功能体验(一)
日期: 2004-09-01
作者: 2002PP
Struts 1.2.2于昨天正式发布了,相信Struts Fans们一定是迫不及待的想要体验一把吧.
下面要介绍的就是我的Struts 1.2.2的初次体验.
(-) org.apache.struts.action.Action的改动.
在Action类中增加了addMessages、addErrors、getErrors、getMessages四个方法
便于处理ActionMessages和ActionErrors.
I. protected void addMessages(
HttpServletRequest request,
ActionMessages messages)
II. protected void addErrors(
HttpServletRequest request,
ActionErrors errors)
III. protected ActionErrors getErrors(HttpServletRequest request)
IV. protected ActionMessages getMessages(HttpServletRequest request)
下面的代码片断是关于ActionMessages的(ActionErrors的例子类似):
ActionMessages messages=getMessages(request);
//xx.xx.xx代表Resource Bundle中的Key值.
ActionMessage msg=new ActionMessage("xx.xx.xx");
messages.add(ActionMessages.GLOBAL_MESSAGE,msg);
addMessages(request,messages);
//在1.2.2中不必调用saveMessages将ActionMessages对象保存到request.
//因为,在addMessages中已经包含了此功能.
//具体可参见Struts 1.2.2的Action源代码.