How Can I Use The Same Error Page For Multiple Error Codes In Tomcat?
Solution 1:
If you're using a Servlet 3.0 container, such as Tomcat 7.0, then you can just omit the <error-code>
(or <exception-type>
) element to make it a global default error page.
<error-page>
<location>/string_error.jsp</location>
</error-page>
Since Servlet 3.0 those elements are namely optional.
However, if you're not on Servlet 3.0 yet, then you'd have to configure it at the container level. In for example Tomcat 6.0 (which is a Servlet 2.5 container), you'd need to create a custom error report valve class. You can then specify it as errorReportValveClass
attribute of the <Host>
element in /conf/server.xml
file.
For other containers, consult their documentation.
Solution 2:
You can add error-page
elements by either the error-code
or the (java) exception-type
in Tomcat. I do not think it can be made general as you have suggested.
<error-page>
<error-code>404</error-code>
<location>/404error.html</location>
</error-page>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/someJavaException.html</location>
</error-page>
Post a Comment for "How Can I Use The Same Error Page For Multiple Error Codes In Tomcat?"