tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vladimir Mokrozub <...@itc.tambov.gov.ru>
Subject empty error page when using sendError()
Date Fri, 10 Aug 2012 07:48:51 GMT
Hello,

I have a problem (tried Tomcat 7.0.29 and Glassfish 3.1) with
displaying an error page when exception is thrown and processed by
another servlet.

Here is what I've added to web.xml:
---------------------
<error-page>
	<exception-type>java.lang.Throwable</exception-type>
	<location>/ErrorHandler</location>
</error-page>
---------------------

Here is a test servlet that throws an exception:
---------------------
@WebServlet("/TestServlet")
public class TestServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		throw new RuntimeException("TestServlet exception");
	}
}
---------------------

And here is ErrorHandler servlet:
---------------------
@WebServlet("/ErrorHandler")
public class ErrorHandler extends HttpServlet {
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// process exception thrown

		response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
				(String) request.getAttribute("javax.servlet.error.message"));
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}
---------------------

When I type http://<server-name>/TestServlet in the address bar, I get
an empty page instead of default Tomcat error page, though the status
code in the header is correct: "HTTP/1.1 500 Internal Server Error".

And even if I add a custom error page in web.xml like this:
---------------------
<error-page>
	<error-code>500</error-code>
	<location>/error.html</location>
</error-page>
---------------------
I still get an empty page instead of error.html.

When I try to send error page directly from ErrorHandler using
HttpServletResponse, it works fine and page is displayed, so it seems
the problem is with sendError() method. Is this an expected behaviour or
some sort of bug?



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


Mime
View raw message