On Jan 12, 2009, at 3:34 PM, Caldarale, Charles R wrote:

Don't think so. Does your code happen to call response.setStatus(200) somewhere along the way?

- Chuck




Well at first I didn't think so, but now I am wondering....

After adding some more instrumentation I have determined that I am inadvertently setting the status to 200.


I was replicating the problem with this servlet:

package opendap.experiments;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;

public class SendErrorTest extends HttpServlet {

    public void doGet(HttpServletRequest request,
                      HttpServletResponse response) {
        try {
System.out.println("Calling HttpServletResponse.sendError(404)");
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
System.out.println("HttpServletResponse.sendError(404) returned.");

        }
        catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}


And a simple document service servlet:

    <servlet-mapping>
        <servlet-name>docs</servlet-name>
        <url-pattern>/docs/*</url-pattern>
    </servlet-mapping>

With this error-page:

    <error-page>
        <error-code>404</error-code>
        <location>/docs/error404.html</location>
    </error-page>


I added some instrumentation and looked at the logs and saw that when the sendError() method is called in the SendErrorTest servlet the call returns immediately. And is followed by a the docs servlet receiving a request for the error document, which since it is successfully returning a document sets the HTTP status to 200.

Is sendError() using a redirect?

Is there a way to set the value of the <location> element in the error- page declaration so that tomcat just grabs the file from the context directory?

The java servlet spec (2.4) says:

"If the sendError method is called on the response, the container consults the list of error page declarations for the Web application that use the status-code syntax and attempts a match. If there is a match, the container returns the resource
as indicated by the location entry."

So what does "the container returns the resource as indicated by the location entry" mean for tomcat?


Is there an example of a design pattern you can point me to?

Thanks,

Nathan






= = =
Nathan Potter                        ndp at opendap.org
OPeNDAP, Inc.                        541.752.1852



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to