Restart Tomcat and access a non-existent URL on a path served by your Tomcat Other hints Remove any other error-page elements and insert into webapps/ROOT/WEB-INF/web.xml: Out.write("Exception Message:"+throwable.getMessage()) Įnter the jvmhost directory and compile the code, for example with javac -cp ~/appservers/apache-tomcat-7.0.39/lib/servlet-api.jar ErrorHandler.java Out.write("Exception Name:"+throwable.getClass().getName()+"") Out.write("Servlet Name:"+servletName+"")
Public class ErrorHandler extends HttpServlet
APACHE TOMCAT ERROR CODE
Save the below code into webapps/ROOT/WEB-INF/classes/com/jvmhost/ErrorHandler.java package com.jvmhost An example of custom exception and error handler servlet Then access a non-existent URL on a path served by your Tomcat to see your custom message. To verify it, add error-page element to webapps/ROOT/WEB-INF/web.xml and create webapps/ROOT/error/404.html with your content.
Starting from Servlet 3.0 (Tomcat 7) you can also use general error page/handler: Before Servlet 3.0 specification (Tomcat 7.0.x) you could define error page for either exception or response code using error-page element this way: In Tomcat, error pages are defined in web.xml - either global one or application specific one. You can also edit the file directly in public_html.ĭefining error pages for paths/URLs served by Tomcat You should get the message that you defined in cPanel in custom 503.shtml page. Now shutdown your Tomcat and access your website. Go to Java Control Panel - Mappings and add /503.shtml to Exclude section. In such case you need to additionally ensure /503.shtml is unmapped from being proxied to Tomcat. But if all your requests are proxied to Tomcat (catch-all mapping for root URL '/' is our default setting) this file will be unreachable. This action will save 503.shtml in your public_html directory. Check again in 15 minutes or better report the problem to user at mailbox dot com". For example we can change the generic 503 shown when our Tomcat is down or overloaded to " We seem to be overloaded. To change the generic messages to your own ones login to cPanel and choose Advanced - Error Pages. Defining custom error pages for paths/URLs served by Apache
In case of WHM/cPanel server generic messages are defined in /etc/httpd/conf/includes/nf.ĥ03 - Service Temporarily Unavailable This is generic message from webserver when Apache cannot contact Tomcat to proxy requests to it.Ĥ04 - The requested resource is not available Can be generated by Tomcat or by Apache depending on which of them is set to serve the request.Ĥ03 - Forbidden Generated by Apache if permissions do not allow access to the resource. By default, when Tomcat is down then generic error message will be produced by Apache. In Java Control Panel you can define which URLs are served by webserver and which ones by application server (let's refer to it as Tomcat from now on). In our environment error pages are either served by Apache webserver or by your application server (Tomcat in below examples) depending on mapping scheme you set. Published on in Control Panels Java TomcatĬustom error pages may help you to unify look of all content served by your website no matter if it is served by Tomcat, by Apache or both.