Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session timeout in filter detection?

 
Michal Malik
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm on this problem for all day and I must be totally idiot, because I don't know solution
My problem:
In aplication session timeout is setted to 30 minutes. Question is HOW can I detect session timeout in Filter? I have to detect it when user perform some server-action but before bean method is called. I'm using filter, because I have to send customized ServletResponse to client when session timeout is detected.
Is there any solution? I'm really lost
Thanks and sorry for my bad english...
 
Kumar Raja
Ranch Hand
Posts: 547
2
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You do have access to HttpServletRequest in your filter, from which you can get the session. Once you have the session, you can check it how long it is been inactive and take action accoridingly. Is this what you are looking for ?
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
look at HttpSessionListener for your problem .
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In aplication session timeout is setted to 30 minutes. Question is HOW can I detect session timeout in Filter?


Are you asking how to detect if the session has timed out? A call to request.getSession(false) would return a null value in that case.

cheers,
ram.
 
Michal Malik
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replies.
I tried request.getSession(false) , but it always returns session object. I tried change filters order witn no effect. Whenever session for client timeouted and I tried to contact server, HttpServletRequest holds new session. What now? This filter is first in web.xml so I think it coudn't by affected by any other in filter pipeline.
Or is there something in web.xml I have to define?

Michal
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best way to tell if a session has timed out is to bind a scoped variable to the session (using setAttribute()) and then testing for it. When a session is destroyed, so are its variables.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic