• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

HttpSession lifetime and storage

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 489
Eclipse IDE Tomcat Server Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks ram...
 
Pay attention! Tiny ad!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic