You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Hussein Badakhchani <hu...@xensia.com> on 2003/08/31 03:36:00 UTC

Request dispatcher error handling behavior

Hello,

My application uses a controller servlet to dispatch requests to a view
servlet in another web app. Both web applications are deployed in an EAR
file running on Jboss-3.2.1-Tomcat-4.1.24.

Dispatching code:

String view = request.getParameter("view");
RequestDisptcher dispatcher =
this.getServletContext().getContext("/view").getRequestDispatcher("/servlet"
+ view);

If the URL given to the request dispatcher does not exist then the server
404 error page is displayed. I have tried to customize this error page
firstly by defining an error page in the web.xml file of the Controller
webapp. My custom page is displayed when attempting to visit non existent
URLs under the controller context but is not displayed when the request is
dispatched to the view context. I then also all updated the view webapp
with it's own error pages and tested these in the same manner. Again
although the page is displayed when visiting the URL directly it is not
displayed when the request is dispatched.

Finally I have tried to change the server error page by defining an error
page in the server web.xml file by adding:

<error-page>
        <error-code>404</error-code>
        <location>/controller/jsp/404.jsp</location>
</error-page>
This did not work at all and the default error pages are still displayed.


SRV.8.5 in the servlet 2.3 specification states:

If the servlet that is the target of a request dispatcher throws a runtime
exception or a checked exception of type ServletException or IOException,
it should be propagated to the calling servlet. All other exceptions
should be wrapped as ServletExceptions and the root cause of the exception
set to the original exception before being propagated.

This suggests to me that the error page associated with the calling webapp
would be displayed if an error occurs in the target servlet. Is this
correct or have I misunderstood:

SRV.9.9.2 Error Pages

The error page mechanism described does not intervene when errors occur in
servlets invoked using the RequestDispatcher. In this way, a servlet using
the RequestDispatcher to call another servlet has the opportunity to
handle errors generated in the servlet it calls.

Any help would be most appreciated.

Cheers Hoos.


--
Hussein Badakhchani     <hussein(at)xensia.com>   t:+44 (0) 7801 816 143
Xensia LLP, London UK   www.xensia.com