• Post Reply Bookmark Topic Watch Topic
  • New Topic

Are there any rules or limitations to set <error-page> attributes in web.xml ?

 
yan ming
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are there any rules or limitations to set <error-page> attributes in web.xml ?
for example :
We should use <error-code> and <exception-type> in the same <error-page> tag.

but can I use multiple <error-code> in one <error-page>?
Or. What if I want catch java.lang.NullPointException and java.lang.Exception, (if it works) could I write them in the same <error-page>
or does the order matter?

Thanks.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is a great question.

Ideally there are no limitations / rules to set the <error-page> attribute in web.xml. You can map any number of error codes to be handled in a error page and the container would do that work for you. For example you can request the container to handover /error.jsp for both HTTP status codes 303 and 404.


What if I want catch java.lang.NullPointException and java.lang.Exception, (if it works) could I write them in the same <error-page>


It is NOT a good practice and you should never catch/handle this NullPointerException through this <error-page> attribute. You should write your code in such a way that there is no NullPointerException gets triggered. The best way to write such code is to validate the inputs and ensure that the objects are NOT null before you invoke any methods on the object.
 
yan ming
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.
But I still got confused about the limitations. So please let me ask more specifically.

Question1:
Are the following error-page declarations code valid ?
I put <exception-type> and <error-code> togetger like this:
<error-page>
<exception-type>java.lang.ArithmeticException</exception-type>
<error-code>304</error-code>
<location>errorpage.jsp</location>
</error-page>


Question2:

What happens if ArithmeticException occurs?

<web-app>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location> Throwable.jsp </location>
</error-page>
<error-page>
<exception-type>java.lang.ArithmeticException</exception-type>
<location> ArithmeticException.jsp </location>
</error-page>
</web-app>
 
Stefan Evans
Bartender
Posts: 1822
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question: Have you tried it?
What happens when you do?
Is it valid according to the xsd for a deployment descriptor?

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!