I am using Apache Tomcat v7.0.63 which is hosting 4 different applications. One of the applications has the list of Error pages.
Now we want to make it generic so that the other applications too can make use of the same error pages. In this way, we do not need to keep duplicate files in all the web applications. We want to keep all the error pages somewhere under tomcat/errorPages directory or tomcat/conf/errorPages directory.
I tried modifying /tomcat/webapps/MyApplication/WEB-INF/web.xml file as below and it is not working. Can anyone please help?
</error-page>
<error-page>
<error-code>404</error-code>
<location>/../../errorPages/errorPage404.html</location>
</error-page>
And errorPage404.html is placed in /tomcat/errorPages directory.
Since Apache Tomcat version 9.0, you may define the ErrorValve on your server.xml under your Host definition with errorCode.nnn (where nnn is the HTTP error code) pointing to a UTF-8 encoded HTML page, as described at configuration information.
So, your server.xml should include on your main host:
<Host appBase="webapps" autoDeploy="false" name="localhost">
<!-- ... your other configs ... -->
<Valve className="org.apache.catalina.valves.ErrorReportValve" errorCode.404="<path to your html, may be relative to $CATALINA_HOME or absolute>"/>
</Host>
This avoids the need to define a different error page on every project or to include a global ROOT.war with error pages defined on global web.xml, as stated in the previous answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With