views:

134

answers:

4

I get jsp exceptions causing a forward to my error page when I put this at the top of my JSPs...

<%@ page errorPage="/error.page" %>

but when I try to do it globally with web.xml like so:

<error-page>
    <exception-type>java.lang.Throwable</exception-type>
    <location>/error.page</location>
</error-page>

I just get a blank page... I've also tried putting /error.jsp in the location element.. but no love with that either..

I am triggering an exception with a jsp that just contains this:

<%if(true)throw new RuntimeException("test exception");%>

I do see the exception in the console from tomcat but I just can't get that error page to show without a directive on every jsp... am I missing something simple here?

UPDATE:

/error.page is mapped (using spring) the contents are this:

<%@ 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 hit the page directly with no error.

UPDATE:

If you have this problem... make sure you don't have filters swallowing exceptions in your chain! see my answer below.

+1  A: 

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

I suspect that's exactly the reason.
Alexander Pogrebnyak
the page is a valid mapping and is very simple for the moment and returns no errors.. I added it to the question.. I have also tried a plain old jsp
danb
how about using </error-code> instead of <exception-type>? like <error-code>500</error-code>. matching on exception types is trickier i think.
no change in behavior when I tried that... for what it's worth, the blank page that comes back has a status of 200
danb
Rightclick the blank page in browser, view source, do you see anything?
BalusC
Nope.. it was a zero byte response... see my answer below for the solution to this mystery! thanks for your help guys
danb
A: 

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

Also, if you are using the directive as well as the DD, the directive will always take precedence.

Epitaph
I removed the directive to try and get the DD working. The url is correctly mapped
danb
Could you restart the tomcat server and try again? Any changes to DD requires restart.
Epitaph
I've restarted and done clean builds more times than I can count today.
danb
+1  A: 

Make sure that if /error.page maps to a servlet, that Servlet implements all relevant do methods ( at least doPost and doGet ).

I had faced a similar problem ( blank page, nothing displayed ), because in my initial implementation I've only implemented doGet.

The actual do calls can converge on a single method, because handling of the errors is very similar in most cases.

Alexander Pogrebnyak
error.page is mapped and comes up as it should when I surf to it.. I'm just using the spring SimpleUrlHandlerMapping to map .page urls to .jsp files for now.. but even if I switch to a plain old jsp in the DD I still get the blank page.. even when the jsp is basically just html.
danb
@danb. I suggest you map it to servlet and verify that servlet's doGet/doPost methods get called when exception is thrown.
Alexander Pogrebnyak
I'm not sure what's going on.. I mapped a very simple servlet to /error.err and put that in there... it doesn't hit it.. but I can hit it manually no prob.
danb
@danb. Override `doService` in your Servlet and see if you are hitting that. Also, remove `<%@ page errorPage="/error.page" %>` directive from your JSP. With error-page you should get to that page anyway
Alexander Pogrebnyak
I overrode all the do*() and service() methods and just write out some debug output... no love. I have also now tried setting development mode to false for jasper.. no help there either.
danb
I do not have the errorPage directive anywhere now... for what it's worth
danb
+1  A: 

Unreal... it turns out there was a filter in the chain that was swallowing and spitting out the exception... so it never propagated up high enough to be handled by the container! bad form! I took that out and now everything works as expected... sorry for the noise.

danb
Happens to best of us :) You're however eligible to accept this answer.
BalusC
It says I have to wait 2 days to accept... oh well.. back to creating problems for myself... thanks again.
danb