wood burning stoves*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Session related query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Session related query " Watch "Session related query " New topic
Author

Session related query

Sagar Shroff
Ranch Hand

Joined: Jun 07, 2011
Posts: 208

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 ??


OCJP-90%,OCPWCD-95%
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1635
    
  23

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

Joined: Jun 07, 2011
Posts: 208

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

Joined: Apr 07, 2010
Posts: 1635
    
  23

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

Joined: Jun 07, 2011
Posts: 208

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

Joined: Apr 07, 2010
Posts: 1635
    
  23

You are welcome

Regards,
Frits
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session related query
 
Similar Threads
sendRedirect not throwing IllegalStateException
session issues with Ctrl-N
Need to split up servlet
servlet exception error in my code(urgent)
Why am i getting NullPointerException but runs properly