You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Les Hartzman <lh...@codexa.com> on 2001/02/08 01:36:37 UTC

Custom error pages from servlets?

Using Tomcat 3.2.1, is it possible to define/display custom error pages
based on errors that occur within a servlet?  No JSPs are used; this is a
servlet/EJB environment.

I've seen in the spec  for web.xml that there is an error-page element for
either a general error code or an exception type.  But is final granularity
possible based on some servlet action?

Thanks.

Les


Re: Custom error pages from servlets?

Posted by Pete Ehli <pe...@teleport.com>.
catch try blocks - out.println(Your custom error message!);
-- Pete --
----- Original Message -----
From: "Les Hartzman" <lh...@codexa.com>
To: <to...@jakarta.apache.org>
Sent: Wednesday, February 07, 2001 4:36 PM
Subject: Custom error pages from servlets?


> Using Tomcat 3.2.1, is it possible to define/display custom error pages
> based on errors that occur within a servlet?  No JSPs are used; this is a
> servlet/EJB environment.
>
> I've seen in the spec  for web.xml that there is an error-page element for
> either a general error code or an exception type.  But is final
granularity
> possible based on some servlet action?
>
> Thanks.
>
> Les
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, email: tomcat-user-help@jakarta.apache.org
>
>


Re: Custom error pages from servlets?

Posted by Kief Morris <ki...@bitbull.com>.
Les Hartzman typed the following on 04:36 PM 2/7/2001 -0800
>Using Tomcat 3.2.1, is it possible to define/display custom error pages
>based on errors that occur within a servlet?  No JSPs are used; this is a
>servlet/EJB environment.
>
>I've seen in the spec  for web.xml that there is an error-page element for
>either a general error code or an exception type.  But is final granularity
>possible based on some servlet action?

I'm not sure what you mean by that last sentence. You can throw
whatever exceptions you want in your servlet to force handling by
a particular error page. Create custom exception subclasses and
throw those in your servlet.

<error-page>
    <exception-type>com.myco.myproject.FooException</exception-type>
    <location>/servlets/FooExceptionServlet)</location>
</error-page>

Section 9.8 of the 2.2 specification explains how to find the error conditions in 
your servlet.

Note that there has been a bug which causes Tomcat to choke if you use
a non JSP/servlet resource to handle error-pages, i.e. using a flat HTML page
kills it. I'm not sure if this is still a bug. 

Kief