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:
While the HTTP 500 error page would like similar to this:
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:
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.
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.