Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Session related query

 
Ranch Hand
Posts: 209
Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey can someone explain me this statement which has been mentioned in Head first

"A session will become invalid as soon as the user closes all browser windows" -It has been mentioned as a wrong answer in that question.

now i was practicing sessions and i m getting a conclusion that suppose i create a session

when i execute this jsp the first time obviously the value of attr1 will be null,then when i refresh i get the value shroff.So far good.
Now when i close my browser and then again start it and execute the jsp i will get null value for attr1,which means that when i close my browser the session gets invalidated ?
Am i right ?
Q1: if so then why is the above statement false ??

Q2:Also another thing i noticed is that when i restart tomcat the session doesnot get invalidate.So is session browser related thing ??

Q3: in the above code i havent set any time-out value in jsp and neither in my DD,and when i call s.getMaxInactiveInterval() then i am getting 1800
.Is this container specific ??

 
Creator of Enthuware JWS+ V6
Posts: 3346
303
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hey can someone explain me this statement which has been mentioned in Head first


This is a bit of a trick question, the Session is on the Server and doesn't know that all the browser windows have closed. This means that the Session object will still be there until there is a timeout. So eventually it will be invalidated but not because you close all you browser windows....

Q2:Also another thing i noticed is that when i restart tomcat the session doesnot get invalidate.So is session browser related thing ??


That is container specific

Q3: in the above code i havent set any time-out value in jsp and neither in my DD,and when i call s.getMaxInactiveInterval() then i am getting 1800
.Is this container specific ??


Yes

Regards,
Frits
 
Sagar Shroff
Ranch Hand
Posts: 209
Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Frits Walraven wrote:
This is a bit of a trick question, the Session is on the Server and doesn't know that all the browser windows have closed. This means that the Session object will still be there until there is a timeout. So eventually it will be invalidated but not because you close all you browser windows....


But in the above code when i run the jsp the value from the attribute gets printed .Fine.And then when i close my browser and again open the browser call the jsp
then the attribute value shown was null because session gets invalidated at that point ?? why so ?? as i mentioned the default timeout shown was 1800.it does not wait for the timeout ??

Regards,
Sagar.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Posts: 3346
303
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

then the attribute value shown was null because session gets invalidated at that point ?? why so ?? as i mentioned the default timeout shown was 1800.it does not wait for the timeout ??


No, the Session is not invalidated, but by closing your browser you loose the reference (i.e. Session-id contained in a Cookie on the client) to the Session object.

When a Session is created, the container sends a Cookie (with name JSESSIONID) to the client. The client will then return the Cookie, on each subsequent request to the server. When you close the browser your Cookie is removed. That is why when you start a new browser, you will get a new Session.

Regards,
Frits
 
Sagar Shroff
Ranch Hand
Posts: 209
Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ohhhhhhh I get it now !! wow that was a real tricky one !!!

Thanks Frits.Thanks a lot buddy !! you have been really helpful in my certificate !

Regards,
Sagar.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Posts: 3346
303
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome

Regards,
Frits
 
To avoid criticism do nothing, say nothing, be nothing. -Elbert Hubbard. Please critique this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic