{"id":11278,"date":"2022-12-20T12:44:35","date_gmt":"2022-12-20T18:44:35","guid":{"rendered":"https:\/\/www.mrc-productivity.com\/techblog\/?p=11278"},"modified":"2023-08-04T12:28:59","modified_gmt":"2023-08-04T18:28:59","slug":"customizing-tomcat-error-pages","status":"publish","type":"ht_kb","link":"https:\/\/www.mrc-productivity.com\/techblog\/?ht_kb=customizing-tomcat-error-pages","title":{"rendered":"Customizing Tomcat error pages"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Overview<\/h2>\n\n\n\n<p>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. <\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>This post will detail how to customize these default error pages.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation<\/h2>\n\n\n\n<p>The current error pages can be viewed by going to this URL: http:\/\/YOUR_MPOWER_SERVER_ADDRESS:8011\/mrcjava\/servlet\/abc<\/p>\n\n\n\n<p>By default, the 404 error page would look like the following: <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/techblog\/images\/tcerror1.jpg\" alt=\"Default Tomcat 404 error\"\/><figcaption class=\"wp-element-caption\">Figure 1: The default HTTP 404 error screen.<\/figcaption><\/figure>\n\n\n\n<p>While the HTTP 500 error page would like similar to this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"\/techblog\/images\/tcerror2.jpg\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Figure 2: The default HTTP 500 error screen.<\/figcaption><\/figure>\n\n\n\n<p>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. <\/p>\n\n\n\n<p>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.  <\/p>\n\n\n\n<p>Here&#8217;s two examples of customized HTTP 404 and HTTP 500 errors, respectively:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/techblog\/images\/tcerror3.jpg\" alt=\"Default m-Power 404 error\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"\/techblog\/images\/tcerror4.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Error pages such as these are completely customizable with your own HTML &amp; CSS. To customize your own HTTP 404 and 500 error pages, simple create a new directory called &#8216;errors&#8217; in &#8230;\\m-power\\mrcjava. Within this folder create a <strong>404.html<\/strong> and a <strong>500.html<\/strong> file. <\/p>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-info\"><strong>Editor&#8217;s Note: <\/strong>You may download and utilize <a rel=\"noreferrer noopener\" href=\"https:\/\/www.mrc-productivity.com\/techblog\/mrc-files\/tcerrors.zip\" target=\"_blank\">these <\/a>404.html and 500.html pages if you&#8217;d like, or create your own HTML pages via your preferred text-editor.<\/p>\n\n\n\n<p>Next, edit the web.xml file within &#8230;.\\production\\m-power\\mrcjava\\WEB-INF\\ and add these two servlets to the bottom of the file, ensuring they are placed <strong>before the final <code>&lt;\/web-app><\/code> tag.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;error-page&gt;\n&lt;error-code&gt;404&lt;\/error-code&gt;\n&lt;location&gt;\/errors\/404.html&lt;\/location&gt;\n&lt;\/error-page&gt;\n&lt;error-page&gt;\n&lt;error-code&gt;500&lt;\/error-code&gt;\n&lt;location&gt;\/errors\/500.html&lt;\/location&gt;\n&lt;\/error-page&gt;<\/code><\/pre>\n\n\n\n<p>Once done, please restart Tomcat.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230;<\/p>\n","protected":false},"author":12,"comment_status":"closed","ping_status":"closed","template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[152],"ht-kb-tag":[],"class_list":["post-11278","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-administration"],"_links":{"self":[{"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/ht-kb\/11278","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11278"}],"version-history":[{"count":22,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/ht-kb\/11278\/revisions"}],"predecessor-version":[{"id":12023,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/ht-kb\/11278\/revisions\/12023"}],"wp:attachment":[{"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11278"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=%2Fwp%2Fv2%2Fht-kb-category&post=11278"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=%2Fwp%2Fv2%2Fht-kb-tag&post=11278"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}