| Author |
leave a message to client when session expires
|
shivam singhal
Ranch Hand
Joined: Jul 15, 2012
Posts: 157
|
|
hello to all.
when we use session.setMaxInactiveInterval(60) ,, after this i waant to leave message to client that their session has been expired..
any body have idea how to leave message to client??
|
 |
Saket Kumar Sinha
Ranch Hand
Joined: Aug 04, 2011
Posts: 31
|
|
|
I think you can check the HttpSession listener class. we have two methods in that. Session created and SessionDestroyed. that may help
|
 |
shivam singhal
Ranch Hand
Joined: Jul 15, 2012
Posts: 157
|
|
|
oks,, i am able to create sessions and destroy them too.. i have really no problem with that.. my problem is lil-bit different,, its about RESPONSE to CLIENT that their session have been destroyed??
|
 |
Saket Kumar Sinha
Ranch Hand
Joined: Aug 04, 2011
Posts: 31
|
|
Ok.
Why can't we take the servletContext in SessionDestroyed method and call requestDispatcher method on servletContext obj for dispatching it to the page which
shows that your page has expired.
Not sure whether this is the appropriate way to do it
|
 |
shivam singhal
Ranch Hand
Joined: Jul 15, 2012
Posts: 157
|
|
oks...
i have tried dispatching without using ServletContext.. and it dispatches before the expiry of session ..
how,, we can use servletcontext here??
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56185
|
|
Saket Kumar Sinha wrote:Not sure whether this is the appropriate way to do it
It is not. In fact, it is impossible to do that as there is no request and response with which to create the dispatcher.
You will need to create a servlet filter than can check if the session has expired or not. You will know if it has because you will have placed a token or some other object in the session to indicate the the user is logged in. If that object is missing, the session has expired or been destroyed.
Your filter can then take whatever action is required.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
shivam singhal
Ranch Hand
Joined: Jul 15, 2012
Posts: 157
|
|
|
yeah,, its not dispatching,, its sendRedirect
|
 |
Saket Kumar Sinha
Ranch Hand
Joined: Aug 04, 2011
Posts: 31
|
|
Bear Bibeault wrote:
Saket Kumar Sinha wrote:Not sure whether this is the appropriate way to do it
It is not. In fact, it is impossible to do that as there is no request and response with which to create the dispatcher.
You will need to create a servlet filter than can check if the session has expired or not. You will know if it has because you will have placed a token or some other object in the session to indicate the the user is logged in. If that object is missing, the session has expired or been destroyed.
Your filter can then take whatever action is required.
Ya. Thanks Bear. i thought that i can get HttpSession obj from the HttpSessionEvent's getSession() method and then using the HttpSession obj i can get the servletContext and then the requestDispatcher. but we should not create a new session when this SessionDestroyed method is called when the session is destroyed.
Hope i understood your point
|
 |
Saket Kumar Sinha
Ranch Hand
Joined: Aug 04, 2011
Posts: 31
|
|
Ya missed one thing and moreover we dont have request and response object to be passed to the forward method of requestDispatcher .
I got your point now.
Thanks !!
|
 |
 |
|
|
subject: leave a message to client when session expires
|
|
|