开发者

How to keep a variable value same through out the application?

开发者 https://www.devze.com 2023-02-14 13:09 出处:网络
I am creating an application in whic开发者_开发知识库h we can edit the content. Now this change in content should be visible to all. I was using a static variable for that. With that the content chang

I am creating an application in whic开发者_开发知识库h we can edit the content. Now this change in content should be visible to all. I was using a static variable for that. With that the content changes and change is visible to all but after sometime it again initialize to its initial value.

So can you give any suggestion through which I can maintain the change without using the database?


With that the content changes and change is visible to all but after sometime it again initialize to its initial value'

It happens only when your ClasLoader reloads the class containing static property.

You can go for FILE-IO(.xml, .properties) or DB,


I guess you can use Application Context available in JSP (example: http://www.java2s.com/Code/Java/JSP/ApplicationObject.htm) or you can try to keep a singleton class which maintains application level data and instialise it from within the init method of any servlet that is marked for loading at startup of the server.

0

精彩评论

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