Reputation: 103
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.
Upvotes: 3
Views: 11956
Reputation: 569
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.
Upvotes: 4
Reputation: 3914
If you want it to make generic, I suggest you to define the errors in TOMCAT_HOME/conf/web.xml
. It will override default error pages that come with Tomcat
.
<error-page>
<error-code>500</error-code>
<location>/server_error.html</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/file_not_found.html</location>
</error-page>
Make sure to move the error pages to location /webapps/ROOT/
Upvotes: 1