• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

when a session is invalidated ?

 
abinash das
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put it in ServletContext..You will be having values untill context is destroyed/server is shutdown..
 
abinash das
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic