wood burning stoves
The moose likes Struts and the fly likes Session timeout and redirecting to login. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Session timeout and redirecting to login." Watch "Session timeout and redirecting to login." New topic

Session timeout and redirecting to login.

A knibbs
Ranch Hand

Joined: Aug 23, 2006
Posts: 158
Hi again all. I am working on my struts app and I now want to put in a mechanism to handle timeouts. When a user leaves their application for the timeout time, if they click on anything I want them to be redirected to the login page. I have a value that I put in session that I check for to see if the user is logged in/that they have been authenticated. The value is only put in after all authentication.
My question is it there an easy way to intergrate this into my application ? That is to say would it be possible to subclass action and place this test in it and then change all my actions to extend my newly subclassed Action class ? Or would it be better to simply place all of these tests in each Action (this seems quite ugly and does not make good code re-use at all )

I am open to any other suggestions or ideas that anyone might be able to give.

thanks in advance.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
What servlet engine or application server are you using? On my current project this is all handled by Oracle Application Server and I am pretty sure that WebSphere handled this on previous projects.

- Brent
A knibbs
Ranch Hand

Joined: Aug 23, 2006
Posts: 158
I am on Sun's application server.
Arulanand Dayalan
Ranch Hand

Joined: Aug 10, 2005
Posts: 124
Extend the RequestProcessor class and override the processPreprocess method to check if the session is valid. If not valid redirect to the Login Page.

Hope this helps.

Thanks and Regards,
A knibbs
Ranch Hand

Joined: Aug 23, 2006
Posts: 158
Thanks for the suggestion, but I had actually tried that and it didn't seem to work. I couldn't even get a test message to appear in my logs. Is there anything else that one has to do other than extend RequestProcessor ?
Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10441

How about using a Filter and adding the check in the filter?
[ March 06, 2007: Message edited by: Jaikiran Pai ]

[My Blog] [JavaRanch Journal]
A knibbs
Ranch Hand

Joined: Aug 23, 2006
Posts: 158
To be honest I know nothing about filters yet, so perhaps I will put that on the list of things to be done in the future.

As always thanks for the suggestion.
subin john Malikayil

Joined: Mar 08, 2007
Posts: 7
overriding the RequestProcessor is the correct way, i don't know why its not working for you.

because i implemented the same in one of my projects.

after doing all those thigs have you made the entry of your new request processor in the struts_config file?

if you are missing that thats the reason.
I agree. Here's the link: http://aspose.com/file-tools
subject: Session timeout and redirecting to login.
It's not a secret anymore!