将Java对象从一个Struts动作传递到另一个 [英] Passing a Java object from one Struts action to another
本文介绍了将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.
这篇关于将Java对象从一个Struts动作传递到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文