Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is Tomcat's default error page located?

Tags:

java

tomcat

Where are Tomcat's default error pages located or how can I customize them? I wish to beautify and change the look and feel of current error pages of Tomcat.

like image 501
Aniruddha Avatar asked Sep 11 '25 17:09

Aniruddha


1 Answers

The default error pages are created by Java code:

  • the HTML content is created by the ErrorReportValve: see source code,
  • the localized messages are in the LocalStrings_<locale>.properties files of the same package: see the English version.

If you want to replace them with static content, you need to:

  • create a static HTML file, e.g. $CATALINA_BASE/errors/404.html,
  • configure the ErrorReportValve accordingly:
    <Host>
        <Valve className="org.apache.catalina.valves.ErrorReportValve"
               errorCode.404="errors/404.html" />
    </Host>
    

External resources in error pages may cause problem: you must check that no security constraints are defined on those resources.

Edit: This of course works if the web applications don't define any error pages. If a custom error page exists in the application it has priority over the error pages defined in the ErrorReportValve.

Also see:

  • ErrorReportValve documentation
  • I need that it redirects multiple sites to the same error page
like image 123
Piotr P. Karwasz Avatar answered Sep 14 '25 06:09

Piotr P. Karwasz