| Author |
ServletContext
|
George Pavamani
Ranch Hand
Joined: Jan 31, 2002
Posts: 31
|
|
Hi All, I have a question regarding the ServletContext. Q) What happens to the attributes bound to the ServletContext of a web-Application( Using setAttribute()method ) when the entire context is reloaded or when the Servlet Container is restarted??? Q)If the attributes bound to the ServletContext are lost because of the reloading, is there a way we can save the contents of the ServletContext before the loss of data?? Any help in this regard is greatly appreciated. Thanks George
|
 |
nutan prakash
Greenhorn
Joined: Oct 28, 2000
Posts: 16
|
|
All the attributes that are set to the ServletContext are lost when the Servlet Container restarts/reloads. If you want to save the contents of the attributes that were set to ServletContext you can write a ServletContextListener Class which does the job of storing the data in a persistent state (DB or Static files). The Listener is invoked when the ServletContext is destroyed. This happens when the Servlet Container is restarted or reloaded. Regards, Nutan
|
P.Nutan Prakash<br />SCJP2
|
 |
Madhav Lakkapragada
Ranch Hand
Joined: Jun 03, 2000
Posts: 5040
|
|
Well, this can happen due to one or more reasons........lets examine the cause first then the effect. 1. An "ADMIN" shuts down the server. 2. Server crashes. 3. Power loss. While the ServletContextListener approach works for the first case, I don't think it works in the later two cases. So its always the responsibility of the application to maintain its state as needed. I am sure this is mentioned in the Spec., in one form or the other. Anyone wants to volunteer to quote the Spec. if something is said re this? In the last two cases, the application behaves like any other Java program, right? My two cents........ - satya
|
Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
|
 |
George Pavamani
Ranch Hand
Joined: Jan 31, 2002
Posts: 31
|
|
Thanks a lot Satya and Nutan. Is it possible to write a servlet/Java class that would automatically store the contents of the ServeltContext to a external storage from time to time, so that we can prevent loss of data during a powerloss or server crash. Thanks again George
|
 |
Madhav Lakkapragada
Ranch Hand
Joined: Jun 03, 2000
Posts: 5040
|
|
Is it possible to write a servlet/Java class that would automatically store Yes, it is possible. - satya
|
 |
 |
|
|
subject: ServletContext
|
|
|