Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to build server level custom error page in tomcat?

Tags:

tomcat

i have multiple web applications deployed on one tomcat web server. for all deployed web application, i want to display same 404.jsp page if 404 error occurred in any web application.

One way is to put an entry of 404 in each web application's web.xml and give proper location to the 404.jsp.

Is there any way so that all web application will display ROOT's 404 page on 404 error??

Thanks, Pavan

like image 919
Pavan Avatar asked Dec 17 '12 12:12

Pavan


2 Answers

You can add this to the $CATALINA_HOME/conf/web.xml

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

And add a webapp that has the page and will answer to the URL under <location>

like image 92
grekier Avatar answered Nov 15 '22 06:11

grekier


  1. Open web.xml under conf/

  2. goto the bottom of the page.

add these lines for each http error code.

<error-page>
 <error-code>404</error-code>
 <location>/error.jsp</location>
 </error-page>
 <error-page>
 <error-code>500</error-code>
 <location>/error.jsp</location>
 </error-page>

Refer to the screenshot.

enter image description here

  1. create a tiny error.jsp

<html>

<body>

<h1>
    <center>The Page You looking for is not available, please connect with administrator.</center>
</h1>

</body>
</html>

refer to the screenshot

enter image description here

  1. Deploy it into ROOT folder of tomcat

refer to the attached screenshot.

enter image description here

5 results.

enter image description here

like image 41
Pratik Gaurav Avatar answered Nov 15 '22 06:11

Pratik Gaurav