Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Custom Error Messages...

 
Matt Williams
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Matt Williams
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jessica,
That does help. I am checking it out right now.
Matt
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic