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 leave a message to client when session expires Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "leave a message to client when session expires" Watch "leave a message to client when session expires" New topic
Author

leave a message to client when session expires

shivam singhal
Ranch Hand

Joined: Jul 15, 2012
Posts: 215

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: 215

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: 215

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: 60752
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
shivam singhal
Ranch Hand

Joined: Jul 15, 2012
Posts: 215

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 !!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: leave a message to client when session expires
 
Similar Threads
cookies and URL rewriting
HttpSessionListener doesn't listens to the event
Need explanation related to Session.AUTO_ACKNOWLEDGE
destroy sessionContext from EJB?
URLConnection timeout