File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes HttpSession lifetime and storage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "HttpSession lifetime and storage" Watch "HttpSession lifetime and storage" New topic
Author

HttpSession lifetime and storage

akaash singh
Ranch Hand

Joined: Jul 04, 2009
Posts: 45
Hi ,

I am a beginner in servlets . I am studying it from Core Servlets and JSP . I am using eclipse with tomcat plugin(sysdeo) and the browser built in eclipse for practice purpose .

I tried the ShowItems + OrderForm example given in the chapter 9(Session Tracking) . http://volume1.coreservlets.com/archive/Chapter9.html

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 ?

Thanks and Regards
Akash
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12785
    
    5
Servers are allowed to persist sessions to disk and get them back on being restarted - the will be found as long as the client is still using the same cookie values.

Since sessions are located by cookie values, probably restarting eclipse drops the previous cookie identifier.

Bill
akaash singh
Ranch Hand

Joined: Jul 04, 2009
Posts: 45
Thanks William

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 am yet to learn deploying applications , so haven't tried this out.

ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

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.

cheers,
ram.


akaash singh
Ranch Hand

Joined: Jul 04, 2009
Posts: 45
Hi ,
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 ?
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

When does a browser discard a session ?

When the cookie associated with the session (usually the JSESSIONID cookie) expires on the browser.

Correct me if I am wrong : Server discards a session in case of calling invalidate and logout or when the MaxInactiveInterval lapses.

correct

If we do not specify a value for this by calling the setMaxInactiveInterval , what is the default value of this interval ?

I do not know if the JEE spec mandates such a value. In tomcat, it is 30 minutes when I last checked.

cheers,
ram.
akaash singh
Ranch Hand

Joined: Jul 04, 2009
Posts: 45
thanks ram...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HttpSession lifetime and storage