You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Philipp Leusmann <ph...@post.rwth-aachen.de> on 2003/03/28 14:15:35 UTC
Catching ServletExceptions through filter
Hi,
is it possible to catch thrown ServletExceptions through a filter to
generate a custom output?
Or, is there a way to define servlets which are processed if, for instance
an Error 500 is produced?
Thanks,
Philipp
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Catching ServletExceptions through filter
Posted by Tim Funk <fu...@joedog.org>.
You *might* be able to get away with this:
public void doFilter(...) {
try {
...
chain.doFilter(request, response);
...
} catch(ServletException e){
...
RequestDispatcher rd =
request.getRequestDispatcher("/WEB-INF/moreCowbell.jsp");
rd.forward(request,response);
}
}
I think this should work if the chain.doFilter(request, response) does
not commit the response.
An easier (but possibly less flexible) alternative exists in web.xml via
an error-page declaration.
<!ELEMENT error-page ((error-code | exception-type), location)>
<error-page>
<error-code>404</error-code>
<location>/moreCowbell.jsp</location>
</error-page>
-Tim
Philipp Leusmann wrote:
> Hi,
>
> is it possible to catch thrown ServletExceptions through a filter to
> generate a custom output?
> Or, is there a way to define servlets which are processed if, for instance
> an Error 500 is produced?
>
> Thanks,
> Philipp
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org