为什么ActionSupport要实现Serialized

发布于 2024-10-13 21:17:21 字数 42 浏览 2 评论 0原文

Action 类需要什么可序列化?如果有的话,它会在何时以及如何发生。

What is the need for Action classes to be serializable? When and how does it happen, if at all.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

救星 2024-10-20 21:17:21

据我所知,它不需要是可序列化的,并且让 ActionSupport 实现该接口是一个错误。

这是我在该主题上找到的最佳推理(取自此处):

在 Web 框架中使用可序列化对象来实现序列化是很常见的。
几个或原因,例如能够跨域保存状态
服务器重新启动以及在集群中传送对象。

话虽如此,(恕我直言)我认为这是一个设计错误
ActionSupport 实现可序列化。我不相信
上面的内容确实适用于 Action 对象,因为它们是短暂的。
使操作可序列化的选择应该留给
开发人员而不是被框架“强迫”。

As far as I can tell, it doesn't need to be Serializable, and it was a mistake to make ActionSupport implement that interface.

Here is the best reasoning I have found on the subject (taken from here):

It's very common in web frameworks to use Serializable objects for a
couple or reasons, such as being able to preserve state across a
server restart and for shipping objects around in a cluster.

With that said, (IMHO) I believe it was a design mistake to have
ActionSupport implement Serializable. I don't believe that either of
the above really apply to Action objects since they are short-lived.
The choice of making Actions Serializable should have been left to
the developer and not "forced" by the framework.

清晰传感 2024-10-20 21:17:21

这个问题可能不再相关,但我认为这可能会有所帮助。
来自 Sun 开发人员网络

对象序列化是将对象的状态保存到序列的过程
字节数,以及将这些字节重建为活动对象的过程
在未来的某个时间。

那么为什么你可能想要序列化你的对象呢?这就是你需要坚持他们的状态的时候
这样您就可以稍后使用它们或在另一个 JVM 中使用它们。 JVM 可能位于同一台计算机上,也可能通过网络位于另一台计算机上。我认为 ActionSupport 类的情况也是如此。如果您扩展 ActionSupport,您将有机会序列化您的操作并将其通过网络发送以在另一个 JVM 中使用。

This question might not be relevant anymore but I thought this might help.
From Sun developer network:

Object serialization is the process of saving an object's state to a sequence
of bytes, as well as the process of rebuilding those bytes into a live object
at some future time.

So why you might want to serialize your objects? That's when you need to persist their state
so you can use them later or in another JVM. The JVM might be on the same machine or over the network on another machine. I think that's the same case for ActionSupport class. If you extend ActionSupport you'll get the chance to serialize your action and send it over the network to be used in another JVM.

牵你的手,一向走下去 2024-10-20 21:17:21

我不知道为什么一定会这样。但操作类必须扩展 ActionSupport。并根据 http://struts. apache.org/2.0.6/struts2-core/apidocs/com/opensymphony/xwork2/ActionSupport.html ,ActionSupport 实现了 Serialized。所以什么时候问题的答案,它一直在发生:p

i don't know why it must be so. but action classes must extends ActionSupport. and according to http://struts.apache.org/2.0.6/struts2-core/apidocs/com/opensymphony/xwork2/ActionSupport.html , ActionSupport implements Serializable. so the answer to the when question, it happens all the time :p

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文