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.

+2


a source to share


5 answers


Unreal ... it turned out that there was a filter in the chain that was swallowing and spitting out the exception, so it never spread high enough to handle the container! bad tone! I took this and now everything works as expected ... sorry for the noise.



+2


a source


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.

+2


a source


make sure /error.page is a valid mapping. If your error page has errors it will force tomcat to show its generic error page

+1


a source


Usually if you are using /ErrorPage.jsp or / ErrorPage you need to have a JSP file in your webapp / appname / or Servlet directory (with the correct url mapping in the deployment descriptor)

Also, if you use a directive as well as DD, the directive will always take precedence.

0


a source


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/ .

0


a source







All Articles