GeeCON Prague 2014*
The moose likes Servlets and the fly likes Session timeout in filter detection? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Session timeout in filter detection?" Watch "Session timeout in filter detection?" New topic
Author

Session timeout in filter detection?

Michal Malik
Greenhorn

Joined: Jan 30, 2010
Posts: 6
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

Joined: Mar 18, 2010
Posts: 519
    
    2

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 ?


Regards
KumarRaja

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

look at HttpSessionListener for your problem .


Save India From Corruption - Anna Hazare.
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

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

Joined: Jan 30, 2010
Posts: 6
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

Joined: Jan 10, 2002
Posts: 61314
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
Consider Paul's rocket mass heater.
 
subject: Session timeout in filter detection?