Configuring Error Pages

The error pages of a web application can be defined in the corresponding file WEBAPP/WEB-INF/web.xml using the error-page entries. Here is an example:

  <error-page>
    <exception-type>java.lang.Throwable</exception-type>
    <location>/global/errors/500.html</location>
  </error-page>

  <error-page>
    <error-code>401</error-code>
    <location>/global/errors/401.html</location>
  </error-page>

  <error-page>
    <error-code>403</error-code>
    <location>/global/errors/403.html</location>
  </error-page>

  <error-page>
    <error-code>404</error-code>
    <location>/global/errors/404.html</location>
  </error-page>

The system searches for the error pages directly below the web application directory. For example, the page for a 401 error defined according to the example above is WEBAPP/global/errors/401.html. Additionally, the Portal Manager will, if the error page does not exist in the specified location, also search for the page below the documentSource which is defined in the /webapps/PM/WEB-INF/pm.xml file. In the case mentioned, the path of the error page would be cmsDir/instance/instanceName/export/online/docs/global/errors/401.html.

If virtual hosts have been defined in the PM (VirtualHostConfig), the error pages defined in the web.xml file must be located in PM/YourVirtualHost/global/errors instead of PM/global/errors/.

If your error page includes other elements, for example stylesheets or images, you need to set the base directory because the links to these additional elements are relative. The base directory can be set by means of the following Javascript code. Include this code in the layout that generates the HEAD section of your error pages.

  <script type="text/javascript">
    <!--
      document.write("<base href='" + location.protocol + "//" +
      location.host + "${document.url}'/>");
    -->
  </script>

This code ensures that the parts included into an error page are taken from the correct directory, regardless of where the error page is actually located.