Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt on <error-page> mechanism

 
Ankur Gargg
Ranch Hand
Posts: 55
Java jQuery Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 207
Eclipse IDE Firefox Browser jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ankur Gargg
Ranch Hand
Posts: 55
Java jQuery Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 207
Eclipse IDE Firefox Browser jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
Java jQuery Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 207
Eclipse IDE Firefox Browser jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic