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 when a session is invalidated ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "when a session is invalidated ?" Watch "when a session is invalidated ?" New topic
Author

when a session is invalidated ?

abinash das
Ranch Hand

Joined: Apr 26, 2008
Posts: 52
Actually when a session object gets nullified/destroyed,

1-When invalidate() is called explicitely.
2-When the window is closed.

if say i want some values even after a window is closed what
should be the right approach.
swapnil dangore
Ranch Hand

Joined: Jun 05, 2006
Posts: 46
Put it in ServletContext..You will be having values untill context is destroyed/server is shutdown..


Cheers<br />-------------<br />Swapnil<br /> <br />SCJP5-81%<br /> <br />"Dictionary is the only place where Success come before Work"
abinash das
Ranch Hand

Joined: Apr 26, 2008
Posts: 52
Is it wise to add values in Context,
because, the Context will be common to all active users right,then there is a chance of
data coruption.
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874



Actually when a session object gets nullified/destroyed,

1-When invalidate() is called explicitely.
2-When the window is closed.


Session starts from the first request from the browser to until say browser is closed or timed out or called invalidate().
You cant possibly get anything from session once its invalidated. if needed store it in DB...( if storing in context is not suited for your apps.)
Uli Hofstoetter
Ranch Hand

Joined: Nov 24, 2006
Posts: 57
abinash das wrote:Actually when a session object gets nullified/destroyed,

1-When invalidate() is called explicitely.

Yes

abinash das wrote:
2-When the window is closed.


No. The servlet container does not know, when the browser window is closed, as http is a stateless protocol with no permanent connection between sever and client. It is always request - response ... (ignoring some AJAX frameworks keeping an open connection)

So i would say
2 - session times out (which will also happen, when the browser is closed)
3- server shutdown or crash (if the session is not persisted to survive the server restart.

Regards,
Uli


SCEA5, Certified ScrumMaster
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Uli Hofstoetter wrote:
abinash das wrote:Actually when a session object gets nullified/destroyed,

1-When invalidate() is called explicitely.

Yes


calling invalidate on session doest not make session as null . still you can call getServletContext on session . it wont throw NPE

Hope this helps
abinash das
Ranch Hand

Joined: Apr 26, 2008
Posts: 52
Uli Hofstoetter wrote:
abinash das wrote:Actually when a session object gets nullified/destroyed,

1-When invalidate() is called explicitely.

Yes

abinash das wrote:
2-When the window is closed.


No. The servlet container does not know, when the browser window is closed, as http is a stateless protocol with no permanent connection between sever and client. It is always request - response ... (ignoring some AJAX frameworks keeping an open connection)

So i would say
2 - session times out (which will also happen, when the browser is closed)
3- server shutdown or crash (if the session is not persisted to survive the server restart.

Regards,
Uli


So, is that mean i can use the session object as a container even if i am closing the window.

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

abinash das wrote:
So, is that mean i can use the session object as a container even if i am closing the window.


you cant invalidate a session on client. it will live on server untill the session is invalidate by server .
PavanPL KalyanK
Ranch Hand

Joined: Feb 28, 2009
Posts: 212
you cant invalidate a session on client. it will live on server untill the session is invalidate by server .


You mean to say that

calling session.invalidate()will results in losing the data which is set up in session.setAttribute()?

and

But its refrerence will not point to null.

Can you clarify me on this .
Mohamed Inayath
Ranch Hand

Joined: Nov 22, 2004
Posts: 124

1. Session invalidates the current session -Invalidates current session and unbinds any objects bound to it.

2. Session timeout happens when there is an inactivity(configurable value in web.xml) from the user from same browser (Closing the browser window is an instance of that).

One can keep data in servlet context if it should be available for the all the requests.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: when a session is invalidated ?
 
Similar Threads
Sessions in JSP page
close window listener???
About Sessions
Window session problem
Clear firefox cookies on closing the window