This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
In this a HttpSession object is created and arraylist object is added to it. This arraylist stores the items ordered . Each time the user orders an item it is stored in the object . No method except for getAttribute and setAttribute is called on the session object
The example works fine .
But once I stop the server and restart it(from within eclipse) and run the example(without closing eclipse) , the session persists. However if i stop the server and then restart eclipse and then run the example , the session is deleted and a new session is created .
Why is it so ? Shouldn't the session be destroyed on restarting the server . And if no , the why does it gets destroyed on restarting eclipse ?
So is it that the client i.e. the browser provided by eclispe maintains cookies as long as eclipse is running , irrespective of whether the server has been stopped ? If I were to run it manually , (that is to say copy the application into web-apps , start tomcat manually and use a proper browser) would the session persist on restarting the server ?
I do not know about the eclipse browser, but normally browsers store the cookie as long as they are instructed to do so which happens when the cookie is first set on the browser. Whether the session would persist on a server restart depends on how you have configured the server. Tomcat I believe, by default, does so. Do note that the cookie would have to still arrive on the request to the server (after the restart) and that would happen only if it has not expired on the browser.
Joined: Jul 04, 2009
I think it will only be clear once I deploy the application . However I have the following doubts :-
- When does a browser discard a session ?
-Correct me if I am wrong : Server discards a session in case of calling invalidate and logout or when the MaxInactiveInterval lapses.
If we do not specify a value for this by calling the setMaxInactiveInterval , what is the default value of this interval ?