IntelliJ Java IDE
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
Register / Login
JavaRanch » Java Forums » Professional Certification » Web Component Certification (SCWCD/OCPJWCD)
Reply 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: 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
 
Threads others viewed
doubt in error page for DD
error-page doubt
Doubt on send Error
filter dispatcher doubt
error page doubt
IntelliJ Java IDE

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture