• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Handling Exceptions

 
pavanasree vasireddy
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai,
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
<global-exceptions>
<exception key="error.required" type="org.apache.jasper.JasperException"
path="/login.jsp" />
</global-exceptions>

Help me in this regard.

Thanks in advance.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anthony Watson
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
if(session==null)goCrazyNuts();
 
pavanasree vasireddy
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a word of warning - have a look at a previous post of mine regarding timed out session's not returning null!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic