将Java对象从一个Struts动作传递到另一个
问题描述:
在我的一项Struts动作中,我在方法中获得了以下代码:
In one of my Struts action I've got the following code in a method:
...
List<Object> retrievedListOfObjects = c.getListOfObjects();
return mapping.findForward("view");
}
fw_view
导致具有另一个Struts表单的新Struts动作。假设此表单具有以下字段
fw_view
leads to a new Struts action with another Struts form. Let's say this form has got among others the following field
List<Object> listOfObjects;
我现在要传递 retrievedListOfObjects
是否可以将其存储在会话中?
Is this possible without storing it in the session?
答
您可以将其存储为请求属性。
you can store it as a request attribute.
request.setAttribute("listOfObjects", listOfObjects);
,然后在操作中将其转发给
and then in the Action that is forwarded to
List<Object> listOfObjects = (List<Object>)request.getAttribute("listOfObjects");
鉴于设置请求属性时可以给它们赋予有意义的名称,应该考虑设置许多属性而不是设置一个大对象列表。
Given that when setting request attributes you can give them meaningful names, you should consider setting many attributes rather than setting one big list of objects.