This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
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


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » 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: 51

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

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

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt on <error-page> mechanism
 
Similar Threads
error-page doubt
filter dispatcher doubt
Doubt on send Error
doubt in error page for DD
error page doubt