wood burning stoves*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Doubt on <error-page> mechanism Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Doubt on <error-page> mechanism" Watch "Doubt on <error-page> mechanism" New topic
Author

Doubt on <error-page> mechanism

Ankur Gargg
Ranch Hand

Joined: Sep 11, 2011
Posts: 55

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: 207

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.


Piyush
Ankur Gargg
Ranch Hand

Joined: Sep 11, 2011
Posts: 55

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: 207

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: 55

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: 207

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Doubt on <error-page> mechanism
 
Similar Threads
Doubt on send Error
error page doubt
error-page doubt
doubt in error page for DD
filter dispatcher doubt