从 Struts 1.3 Action 子类传递到 JSP 页面的大数据
我想从 Action 子类向 JSP 页面发送大量数据。
我的问题:
将数据从 Action 子类发送到 Struts 中的 JSP 页面的最有效方法是什么?
这样做我会遇到什么问题?
如果我使用
request.setAttribute()
在请求上放置两个大ArrayList
并在 JSP 页面上读取该请求会怎么样?
I want to send a large amount of data to a JSP page from an Action subclass.
My questions:
What is the most effective way to send data from an Action subclass to a JSP page in Struts?
What problems can I face doing so?
What if I put two big
ArrayList
s on a request usingrequest.setAttribute()
and read that request on the JSP page ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您从 Struts 1/2 中的操作返回大量数据到 JSP 时,您并不是通过线路发送它。它不是重定向,而是转发。这意味着从操作返回的数据将可通过 JSP 中的引用获得。不涉及复制和网络传输。当然,如果您使用 JSP 和您提供的模型渲染大量内容,则需要花费大量时间将其发送回客户端。但操作和视图 (JSP) 之间的通信本身是在处理一个请求期间发生在内存中的。没什么好担心的。
我认为这适用于将模型从控制器返回到视图的每个框架 - 没有任何内容被复制,只是引用传递。另外,使用 request.setAttribute 不会复制任何内容,也不涉及克隆。
警告:这不适用于会话属性,会话属性在请求之间持久存在,可能会被序列化和复制等。但是请求属性对于大对象来说是没问题的,只要您确实需要它们(?)
When you are returning large amount of data from action to JSP in Struts 1/2, you are not sending it over the wire. It is not redirecting, but forwarding. This means that the data returned from the action will be available by reference in the JSP. No copying and network transport is involved. Of course if you render a huge content using JSP and the model you've provided, it will take a lot of time to send it back to the client. But communication between the action and the view (JSP) per se happens in-memory during the processing of one request. Nothing to be worried about.
I think this applies to every framework that returns model from the controller to the view - nothing is copied, just reference passing. Also using
request.setAttribute
does not copy anything, no cloning is involved.Warning: this does not apply to session attributes, that are persistent across requests, might be serialized and replicated, etc. But request attributes are fine with big objects, as long as you really need them (?)