JSP中的Bean序列化 [英] Beans serialization in JSP

查看:153
本文介绍了JSP中的Bean序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么有些时候教程会使bean实现Serializable对象而其他人没有?
我知道当我想通过网络发送它时,该对象应该被序列化,这也证明了会话中使用的每个bean都应该实现Serializable对象,JSP页面中定义的bean不应该因为它们不是使用HTTP传输的requeset

Why some times tutorials make beans implement Serializable object and others do not? I know that object should be serialized when I want to send it through a network, so does that prove that each bean used in sessions should implements Serializable objects and beans defined in JSP pages should not since they are not transferred using HTTP requeset

推荐答案


我知道当我想发送它时,该对象应该是
序列化
通过网络,所以证明
每个bean在会话中使用
实现Serializable

I know that object should be serialized when I want to send it through a network, so does that prove that each bean used in sessions should implements Serializable

您似乎相信会话中的对象会在http传输中发送到客户端吗?当然不是这样。转移的内容仅是会话ID(通常在cookie中)。 servlet容器(例如Tomcat)只是在内存中保存会话对象(bean或不是bean),由会话ID索引。

You seem to believe that objects in a session are sent to the client in the http transfer? That's certainly not the case. What is tranferred is only the session id (typically in a cookie). The servlet container (eg Tomcat) just keeps in memory the session objects (beans or not), indexed by the session id.

此外,序列化不仅适用于网络传输,还适用于保存/加载到持久存储(例如磁盘)。

Besides, serialization does not only apply to network transfer, it also applies to save/load to persistent storage (eg disk).

现在,许多servlet容器通常允许(根据设置)持久化会话对象到磁盘,以便它们可以在app-server重启后继续存在。对于那种情况,要使会话对象可序列化是必须的。

Now, many servlet containers usually allow (depending on the settings) to persist the Session objects to disk so they can survive a app-server restart. For that scenario, to have your session objects serializable is a must.

无论如何,实现Serializable接口对于每个java bean都是一件好事,通常它很容易。

Anyway, implementing the Serializable interface is a nice thing to have for every java bean, and usually it's easy.

这篇关于JSP中的Bean序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆