• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

error-page element in web.xml

 
Aaron John
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question regarding this <error-page> element.

I read that you can specify either an <error-code> or <exception-type> inside an <error-page>, but not both under the same <error-page> element. Suppose I have three <error-page> elements in my web.xml, like below:

<error-page>
<error-code>500</error-code>
<location>/jsp/error.jsp</location>
</error-page>

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

<error-page>
<exception-type>NoPermissionException</exception-type>
<location>/jsp/NoPermissionException.jsp</location>
</error-page>

How does it know to redirect to the specified JSP if NoPermissionException is a subclass of Throwable? Also if a NoPermissionException is thrown, the HTTP code is 500, so how does it know to go to NoPermissionException.jsp instead of error.jsp as specified in <error-code>? Please explain this to me. Thank you.
 
Aaron John
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like my post was posted 4 times. Please ignore the rest
 
dema rogatkin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Spec states something like:
The web application may have declared error pages using the exception-type
element. In this case the container matches the exception type by comparing the
exception thrown with the list of error-page definitions that use the exceptiontype
element. A match results in the container returning the resource indicated in
the location entry. The closest match in the class heirarchy wins.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic