File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Custom Error Messages... 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 "Custom Error Messages..." Watch "Custom Error Messages..." New topic

Custom Error Messages...

Matt Williams

Joined: Sep 10, 2001
Posts: 9
OK, I have been racking my brain on how to do this, I have searched high and low and I haven't found a solution to the problem. Is there a way with Tomcat to set up a custom error page when something goes wrong on a page? I can't seem to find anything on this or how to do it.
Thanks in advance.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
That functionality is built in to the JSP spec. In your page directive you set an errorPage url with the (SURPRISE!) errorPage attribute. That URL points to a JSP page that has the attribute isErrorPage="true"
On that page you will have an automatic object named (SURPRISE!) exception. You can then output a stack trace or otherwise pull diagnostic information out of the exception thrown by your page....
This is all discussed in the JSP API documentation.
Any decent servlets and JSP book would have an example.
author of:
Matt Williams

Joined: Sep 10, 2001
Posts: 9
Great, but that doesn't solve the problem unless you add that tag in every page of the application. The application that we are developing has hundred of pages. Tomcat can't just have a setting in the config that will allow all errors to point to a specific page even if it doesn't have the error page set?
P.S. Not sure if the sarcasm is warrented here. I am sure that you have been a Java pro your entire life and never needed to ask for help. Very uncool.
Jessica Sant

Joined: Oct 17, 2001
Posts: 4313

If your application is packaged in a WAR file (Web Application) you can specify error pages in your web.xml (this way you can cover ALL the pages in your app, plus its not tied to one particular app server):
From the Servlet 2.2 spec web.xml -->

Here's an example:

Hope that helps!

- Jessica Bradley
HP Bluestone

- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
Matt Williams

Joined: Sep 10, 2001
Posts: 9
Thanks Jessica,
That does help. I am checking it out right now.
I agree. Here's the link:
subject: Custom Error Messages...
It's not a secret anymore!