> From: Nathan Potter [mailto:[email protected]]
> Subject: Re: Tomcat returns HTTP status of 200 when
> HttpServletResponse.sendError() called.
>
> My guess is I have fouled up the servlet mapping...
It looks o.k. to me (other than the aforementioned /docs mapping), but this
discussion does trigger a memory: as currently coded, the DefaultServlet
doesn't take into account the <servlet-mapping> used to invoke it. It assumes
its references start at the base of the webapp, rather than some number of
directories deeper. I think the code at lines 299 - 302 (6.0.18 level) in the
getRelativePath() method of DefaultServlet should really be:
String result = request.getPathInfo();
if (result == null) {
result = request.getServletPath();
} else {
result = request.getServletPath() + result;
}
Turn on debugging in the DefaultServlet <init-param> to verify that's what's
happening.
You could try implementing your own class that extends DefaultServlet and
overrides only the getRelativePath() method with the above modification to see
what happens. Here's the complete - but untested - code for the suggested
revised method:
protected String getRelativePath(HttpServletRequest request) {
// Are we being processed by a RequestDispatcher.include()?
if (request.getAttribute(Globals.INCLUDE_REQUEST_URI_ATTR) != null) {
String result =
(String)request.getAttribute(Globals.INCLUDE_PATH_INFO_ATTR);
if (result == null) {
result =
(String)request.getAttribute(Globals.INCLUDE_SERVLET_PATH_ATTR);
}
if (result == null || result.equals("")) result = "/";
return result;
}
// No, extract the desired path directly from the request.
String result = request.getPathInfo();
if (result == null) {
result = request.getServletPath();
} else {
result = request.getServletPath() + result;
}
if (result == null || result.equals("")) result = "/";
return result;
}
There are no explicit constuctors for DefaultServlet, so you won't need any
either.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you received
this in error, please contact the sender and delete the e-mail and its
attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]