The errorPage directive works, but the error page in web.xml is not working?
I am getting jsp exceptions causing redirects to my error page when I put this at the beginning of my JSPs ...
<%@ page errorPage="/error.page" %>
but when i try to do it globally with web.xml like this:
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/error.page</location>
</error-page>
I just get a blank page ... I also tried putting /error.jsp in the location element .. but don't like it with that either.
I am running an exception from jsp that just contains this:
<%if(true)throw new RuntimeException("test exception");%>
I see an exception in the console from tomcat, but I just can't get this error page to show without a directive on every jsp ... Am I missing something simple here?
UPDATE:
/error.page is displayed (using spring), this is the content:
<%@ page isErrorPage="true"%>
<html>
<head></head>
<body>
<div class="error">
An error has occurred, the development team has been notified. Sorry for the inconvenience.
</div>
</body>
</html>
I can get directly to the page without errors.
UPDATE:
If you have this problem ... make sure you don't have filters swallowing exceptions in your chain! see my answer below.
a source to share
Make sure that if /error.page
mapped to a servlet, that servlet implements all of the appropriate methods do
(at least doPost and doGet ).
I had a similar problem (blank page, nothing showing) because in my original implementation I only implemented doGet
.
The actual calls do
may converge in the same manner, as error handling is very similar in most cases.
a source to share
As a suggestion, instead of just showing a friendly message to the end user, you should also consider doing something useful with the exception, like logging it or notifying someone that it happened.
You can do this by referring to the various attributes specified in the request, for example:
request.getAttribute("javax.servlet.error.message");
and using these attributes in a bean or inline JSP code block.
More on http://metatations.com/2011/11/20/global-exception-handling-in-java/ .
a source to share