1. Home
  2. m-Power Administration
  3. Customizing Tomcat error pages

Customizing Tomcat error pages

Overview

Many developers of m-Power are familiar with encountering HTTP 404 and HTTP 500 pages in the event a request for Apache Tomcat is not found or a server error has occurred.

In production environments specifically, it can be desirable to provide end-users a more user-friendly and instructional message, which can guide them back to a home page or dictionary menu.

This post will detail how to customize these default error pages.

Implementation

The current error pages can be viewed by going to this URL: http://YOUR_MPOWER_SERVER_ADDRESS:8011/mrcjava/servlet/abc

By default, the 404 error page would look like the following:

Default Tomcat 404 error
Figure 1: The default HTTP 404 error screen.

While the HTTP 500 error page would like similar to this:

Figure 2: The default HTTP 500 error screen.

In production environments specifically, it can be desirable to provide end-users a more user-friendly message, which also provides them a link back to a home page or a dictionary menu.

This is especially true when it comes to HTTP 500 errors, as while a stack trace error (as shown in Figure 2) is helpful for developers, it can appear intimidating and confusing to an end-user.

Here’s two examples of customized HTTP 404 and HTTP 500 errors, respectively:

Default m-Power 404 error

Error pages such as these are completely customizable with your own HTML & CSS. To customize your own HTTP 404 and 500 error pages, simple create a new directory called ‘errors’ in …\m-power\mrcjava. Within this folder create a 404.html and a 500.html file.

Editor’s Note: You may download and utilize these 404.html and 500.html pages if you’d like, or create your own HTML pages via your preferred text-editor.

Next, edit the web.xml file within ….\production\m-power\mrcjava\WEB-INF\ and add these two servlets to the bottom of the file, ensuring they are placed before the final </web-app> tag.

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

Once done, please restart Tomcat.

Updated on August 4, 2023

Was this article helpful?

Related Articles