开发者

Servlet context serializable attribute persistence

开发者 https://www.devze.com 2023-01-11 02:44 出处:网络
I set a servlet context attribute, which is an object of Serializable class. Does it persist after application server restart as session attr开发者_如何学Pythonibutes do?Attributes in servlet contexts

I set a servlet context attribute, which is an object of Serializable class. Does it persist after application server restart as session attr开发者_如何学Pythonibutes do?


Attributes in servlet contexts are not automatically persisted. If you want to persist them you will need to do it yourself.

I don't think persistence of servlet context attributes would be a good idea. There is a non-zero chance that the servlet container will terminate abruptly without giving your webapp a chance to persist its attributes. Your webapp would need to deal with this possibility on restart.


This is not required/specified by the Servlet API. Technically, this depends on the servletcontainer in question. As far as I know, no one does that. You'd like to consult the documentation of the servletcontainer in question. If it doesn't support that, then you need to persist and revive it yourself with help of a ServletContextListener and ObjectOutputStream and ObjectInputStream.

0

精彩评论

暂无评论...
验证码 换一张
取 消