This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Handling Exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Handling Exceptions" Watch "Handling Exceptions" New topic

Handling Exceptions

pavanasree vasireddy
Ranch Hand

Joined: Jun 12, 2004
Posts: 34
I am using using Struts1.1 to develop a webapplication. I am using sessions.
My problem is if I did not perform any operation in the applicaition for a certain period of time session automatically expires and give the following error.

" org.apache.jasper.JasperException"

I want my application to login page whenever this exception occurs.
How do I handle this in struts-config.xml with <global-exceptions>

I have written it like this
<exception key="error.required" type="org.apache.jasper.JasperException"
path="/login.jsp" />

Help me in this regard.

Thanks in advance.
Marc Peabody
pie sneak

Joined: Feb 05, 2003
Posts: 4727

You could have your actions check for a valid session and if none is present send user to logout, a global forward that will send them to the login page.

A good workman is known by his tools.
Anthony Watson
Ranch Hand

Joined: Sep 25, 2003
Posts: 327
I agree with Mark, except that I think the code to check for the session should be put in an intercepting filter. That way, you only need to write the session checking code in one place, rather than in every Action.
Marc Peabody
pie sneak

Joined: Feb 05, 2003
Posts: 4727

Filter would work... except for in the most recent version of WSAD (for anyone out there using it) which has some strange bug where filters don't use the same session as everything else. In any other environment it's a great option.

Checking session in every Action that needs it might not be that bad of solution if not all Actions need it. If they DO, then the filter is certainly a good solution. It's not that much code.
pavanasree vasireddy
Ranch Hand

Joined: Jun 12, 2004
Posts: 34
Thanks for the reply. I don't know how to use filters.

Is there any way of handling it. can you please tell me where I am going wrong while handling the Exception through <global-exceptions> option in stuts-config.xml.

It would be great if you me help out in this with out filters.

Thank you
A Harry
Ranch Hand

Joined: Jan 23, 2002
Posts: 124
a word of warning - have a look at a previous post of mine regarding timed out session's not returning null!
subject: Handling Exceptions
Similar Threads
Built in exceptions in Struts
Struts Exception Handling
404 prob.
Struts (v1.1b3) html:errors property attribute?
global exceptions in struts