aspose file tools*
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Custom Error Messages..." Watch "Custom Error Messages..." New topic
Author

Custom Error Messages...

Matt Williams
Greenhorn

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.
Matt
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
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.
Bill
------------------
author of:
Matt Williams
Greenhorn

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?
Matt
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
Sheriff

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
Greenhorn

Joined: Sep 10, 2001
Posts: 9
Thanks Jessica,
That does help. I am checking it out right now.
Matt
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Custom Error Messages...