• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

strange error-page problem?

 
Steve Ford
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to use a single error page for all exceptions which occur in my jsps, but I have not been able to get this to function properly. This is the relevant part of my web.xml:

<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error.jsp</location>
</error-page>

Now, if my jsp throws a java.lang.Exception it works perfectly and redirects to error.jsp, the problem is that if my jsp throws a subclass of java.lang.Exception the redirect is not occuring. If I explicitly list the exception subclass in the web.xml the container redirects, but obviously I can't do this for all possible exceptions. I thought the problem might be related to throwing unchecked exceptions, but the redirect does not occur regardless of whether the subclass extends Exception or RuntimeException. Any help is appreciated.
 
Scott Duncan
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could just use:



in your jsps and then in error.jsp:



You are probably not wanting to do this in each JSP but it is a viable solution.
 
Steve Ford
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Duncan,

Yes using <%@ page errorPage="error.jsp" %> is a viable solution, and I may have to resort to that, but I would rather set the page for all jsps in the web.xml. Based on what I have said, do you think it could be a problem with the web container? I am using a local wsad server, and I am thinking that maybe this will fix itself once I deploy to a real server?
 
Scott Duncan
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The WebSphere Test Environment (local WSAD server) is for all intents and purposes a real server if not a bit scaled down. However, if you are deploying to WebSphere then this is the expected behavior unless you specify a catch-all error page (read here).

I think if you omit the 'error-code' attribute:



Hope this helps.
 
Steve Ford
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. Specifying a catch-all error page worked fine, and that article clarified the expected Websphere behaviour. However, I can't help feeling that WS is not J2EE compliant here. Take a look at http://java.sun.com/developer/EJTechTips/2003/tt0114.html under the section "Reporting Exception Superclasses" it clearly states that the Web container should look up the inheritance hierarchy until it finds a matching error-page entry in the deployment descriptor. This seems more flexible as you can specify different error pages (or even error handling servlets) for different branches of the exception tree. Too bad because for the most part WAS seems fairly compliant.
 
Scott Duncan
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without reading the spec, let me just say that I feel your pain. Nothing surprises me with IBM and WebSphere. WebSphere is a J2EE certified container so either this check was missed or there is a slight loop hole. I've come to expect these "loop holes" from WebSphere and all containers for that matter. At least it is worked out now....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic