• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

leave a message to client when session expires

 
shivam singhal
Ranch Hand
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64718
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
shivam singhal
Ranch Hand
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah,, its not dispatching,, its sendRedirect
 
Saket Kumar Sinha
Ranch Hand
Posts: 32
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic