File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Why is my error page not invoked? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Why is my error page not invoked?" Watch "Why is my error page not invoked?" New topic

Why is my error page not invoked?

Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436

I'm using Tomcat 6.0.26 with java 1.6 on Mac 10.6.3. In my WEB-INF/web.xml file, I have

However, a particular JSP page dies with a NumberFormatException, which I can view in Tomcat's localhost log file (stack trace at the bottom). However, I am not redirected to the error page I specify above. Instead, the JSP renders half-way and then stops where the error occurs. What do I need to configure to get the error to properly trigger to the error page?

- Dave

Here's the stack trace in the localhost log from the NumberFormatException ...

Ramesh Shanmugam
Ranch Hand

Joined: Sep 13, 2004
Posts: 132

the web.xml entry shown below will be executed whenever there server HTML response code is 500. how ever if you wish to redirect to error page incase of exception, please try the following web.xml entry.

Ramesh Shanmugam - SCJP 1.5
Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436

Thanks for your reply. I added the directive you specified to my WEB-INF/web.xml …

and then on my JSP page, I intentionally caused an exception …

However, I am still not redirected to my error page (instead just getting an incomplete JSP rendering), even though the below stack trace appears in my localhost log. Any other ideas? - Dave

Kris Schneider
Ranch Hand

Joined: Feb 14, 2001
Posts: 71
It looks like the flushing of some of the original JSP's content to the output stream is causing the error page mechanism to fail. Which makes some sense, since the response has already been committed before the exception is thrown. In the long-run, you may want to move that processing into a filter or servlet, but here's something you might try for now - make sure you specify a large enough buffer so that partial contents don't get flushed:

...or just try removing buffer="none" if you have it set...
I agree. Here's the link:
subject: Why is my error page not invoked?
It's not a secret anymore!