Search code examples
javatomcat

Where is Tomcat's default error page located?


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.


Solution

  • 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: