Reputation: 43
I'm attempting to use a servlet to handle errors for a simple web application, and it is working very well for any errors specifically defined with exception-type in my web.xml. However, if I try to send HTML error codes using the HttpServletResponse.sendError method, the web.xml does not seem to pick up the error and simply displays Tomcat's default error page for that particular HTML status code.
My error handling servlet has a couple "catch-all" generic error pages it will generate if it doesn't match a particular error code, so the error simply isn't making its way to the servlet, and I am completely puzzled as to why it's behaving this way.
Here is the relevant snippet from my web.xml:
<error-page>
<error-code>400</error-code>
<location>/Error</location>
</error-page>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/Error</location>
</error-page>
And here is an example of the error I am attempting to send in the servlet:
if (thing.getSizeOfThing() == null || thing.getQuantity() <= 0) {
response.sendError(400);
}
My error handling servlet will display a relevant error page based on the error code or exception type, as well as the servlet that generated the error. As I mentioned, this is working great for exceptions, and not working at all for errors sent using the sendError method.
I have made sure that the issue with minimum content size in the response is not an issue (or shouldn't be) as I am not receiving a browser specific error page, but tomcat's generic 400 error page.
Any help is greatly appreciated!
Upvotes: 3
Views: 2844
Reputation: 43
Solved:
It was an issue with a NullPointerException that I overlooked in the error handling servlet, so tomcat defaulted to its own error page.
Upvotes: 1