tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gautam Sinha" <gaut...@embracenetworks.com>
Subject RE: How to configure a custom page for JSP 404 errors?
Date Wed, 01 Aug 2001 03:05:11 GMT
Pierce Courtney wrote:

Thanks for your replies, but this simply does not work for me ..
.. .. ..
If anyone has actually gotten this to work on Tomcat 3.2.2,
Please let me know how you did it.

--------------------------------------------------------------
Since I needed to display a customized error page, and have it 
working for Tomcat 3.2.1, here are the steps:

Platform: Tomcat 3.2.1 on Windows 2000

1.Create a Java Server Page like below and
  place it in your web app context.
  Lets call it errorHandler.jsp.
  Lets put it in tomcat_home/webapps/myApp/errorHandler.jsp.

<%@ page language="java" %>
<%@ page isErrorPage="true" %>
<html>
<head></head>
<body>
<p>This is a custom message</p>
</body>
</html>

2. Add to your context specific web.xml the following
lines anywhere between the <webapps> and </webapps> tags.
(Not in tomcat_home/conf/web.xml).  If you do not have a
web.xml in your context, copy and paste the following code
in between <webapps> and </webapps> tags and create a 
tomcat_home/webapps/myApp/WEB-INF/web.xml, where your context
is called myApp.

  <!-- Error handler pages -->
  <error-page>
    <error-code>404</error-code>
    <location>/errorHandler.jsp</location>
  </error-page>

3. Restart tomcat. Type a non-existent URL using your context
(say http://localhost:8080/myApp/non-exist.jsp) which you are sure
results in an error code 404 File Not Found, and check that the custom
message appears instead.

Note: If you prefer, you may use a servlet instead of a JSP.  Make
sure you have the servlet defined and do not use the preceding "/"
in the <location> tag.  Use the servlet name instead of the JSP name.
Initially I implemented this using a servlet, but replaced it with a JSP.
I could not get this to work with plain html files.

You may also append the alternate form below if you want to replace
pages with errors resulting from servlet exceptions:

  <error-page>
    <exception-type>java.lang.Exception</exception-type>
    <location>/errorHandler.jsp</location>
  </error-page>

Hope that helps,

Gautam


Mime
View raw message