tags:

views:

404

answers:

1

Thanks to everyone in advance,

I have overwritten HTTPServletResponse that collects headers and also put together a servlet filter that takes those headers and sets them using their proper methods (example: 500 error code uses response.sendError(500)). I am noticing that when this filter is set in the web.xml, any pages that have the errorPage set never get used and the message i receive is the default tomcat 500 message without a stack trace "The server encountered an internal error () that prevented it from fulfilling this request." also nothing is written in the logs about what is happening. I have verified that the filter and the overwritten HTTPServletResponse are not throwing anything. Another interesting note is that if comment out the lines where I am using the sendError method it will use the errorPage specified, but then set the status code to 200.

Thanks again,

Sam

+1  A: 

Well, the #sendError methods do not specifiy, that your custom error pages are to be used. It specifies, that the error condition is sent to the client immediately with flushing the response buffer at the end. Because the Servlet API is more general than the JSP API, the behavior is up to the container implementation. And the easiest way to send the error inside the Servlet layer is to show the container's default error page when using #sendError (that's what Tomcat does).

A solution is to chain the request / response so the servlet container's response processor can delegate to your custom error page instead of sending the error instantly.

oeogijjowefi
Thanks for the response -I went ahead and did this, catching the error in my filter and then executing: request.getRequestDispatcher(ErrorHandlerPath).forward(request, response), but this still does not allow me to set the Status header to 500, it does allow me to circumvent using the errorPage directive etc but in my jsp page that gets executed when there is an exception, a status 200 is still sent. Any ideas?
Sam Ingrassia
You can use HttpServletResponse#setStatus(int) for that. The container must then pick a configured error page.
oeogijjowefi
.setStatus() only really applies for successful requests, errors will override it in (some?/most?) containers
jayshao