Please excuse the cross post to tomcat user mailing list. I am trying to
understand the request dispatchers error handling behavior and want to
know if Tomcat is implementing the specification correctly.

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.

e.g.

http://mydomain/controller/nosuchfile.jsp (displays custom 404 error page)

http://mydomain/controller?view=nosuchfile.jsp (displays default 404 error
page)

http://mydomain/view/nosuchfile.jsp (displays custom error page)

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 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.




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to