| Author |
Doubt on <error-page> mechanism
|
Ankur Gargg
Ranch Hand
Joined: Sep 11, 2011
Posts: 47
|
|
Hi Ranchers
I have a doubt about error page mechanism.
Suppose I am having the below configuration in web.xml
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/first.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.ArithmeticException</exception-type>
<location>/second.jsp</location>
</error-page>
Which JSP shall be called if ArithmeticException is thrown?
I tried on tomcat 6 it gives me result as second.jsp.
Can anyone explain why?
|
|
 |
Piyush Joshi
Ranch Hand
Joined: Jun 10, 2011
Posts: 206
|
|
To look for the answers of these kind of questions you should refer to Servlet specification. If you go to page 126 of specification it says:
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 exception-type
element. A match results in the container returning the resource indicated in the
location entry. The closest match in the class hierarchy wins.
So closest match here in your case is ArithmaticException so it wins! thats it.
|
OCPJP 6, OCE-JSP and Servlet Developer
|
 |
Ankur Gargg
Ranch Hand
Joined: Sep 11, 2011
Posts: 47
|
|
Hi Piyush
I read the same but when I tried on Tomcat 6 it ave me contrary results.
The JSP corresponding to java.lang.Throwable was called in action.
Regards
Ankur Garg
|
 |
Piyush Joshi
Ranch Hand
Joined: Jun 10, 2011
Posts: 206
|
|
Are you sure? In your first post you said that second.jsp was the result, which is as expected:
Ankur Gargg wrote:
I tried on tomcat 6 it gives me result as second.jsp.
|
 |
Ankur Gargg
Ranch Hand
Joined: Sep 11, 2011
Posts: 47
|
|
Hi
Yeah I am very sure that the jsp corresponding to java.lang.Throwable was called.
I agree I was wron in the first post the jsp being displayed is first.jsp,
Regards
Ankur Garg
|
 |
Piyush Joshi
Ranch Hand
Joined: Jun 10, 2011
Posts: 206
|
|
yes you are right! I tried it in tomcat 7.
I think its a bug in Tomcat.
But you have seen what's there in specification, so you are clear from the point of view of exam.
|
 |
 |
|
|
subject: Doubt on <error-page> mechanism
|
|
|