This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Session related query  RSS feed

 
Ranch Hand
Posts: 209
Java Tomcat Server
  • 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
Bartender
Posts: 3121
259
Android Chrome Eclipse IDE
  • 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
Java Tomcat Server
  • 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
Bartender
Posts: 3121
259
Android Chrome Eclipse IDE
  • 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
Java Tomcat Server
  • 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
Bartender
Posts: 3121
259
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome

Regards,
Frits
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!