11
votes

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

2

2 Answers

24
votes

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>

1
votes
  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