wood burning stoves*
The moose likes Tomcat and the fly likes Custom error-page tag drops useful console 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 » Products » Tomcat
Bookmark "Custom error-page tag drops useful console messages" Watch "Custom error-page tag drops useful console messages" New topic
Author

Custom error-page tag drops useful console messages

Lou Pelagalli
Ranch Hand

Joined: Nov 11, 2003
Posts: 150
    
    1
Hi All,

We're using Tomcat 4.0.6.

When using the default implementation and an Exception is thrown, a very user un-friendly "Apache Tomcat/4.0.6 - HTTP Status 500 - Internal Server Error" page appears. We don't want the user's to see this!

However, us techies like it because it tells use where to find our errors under the "root cause" label. Just have to scroll down a little.

So, to present a better looking error page I added the following to the web.xml file.
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/jsp/messagePage.jsp</location>
</error-page>

That works great, but I no longer have anyplace to find the "root cause".

Does anyone know how get a copy of the object that contains contains "root cause" in my messagePage.jsp so I can send it to the console using a scriptlet instead of letting Tomcat send it to the web browser?

Or just some way to get the "root cause" to the console and let the messagePage.jsp do whatever it does.

Thank You in Advance For Your Help,

Lou
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61084
    
  66

If messagePage.jsp is declared as an error page, it will have an implicit exception object available.

Better suggestipn: make your error handler a servlet that can do any amount of error processing you want and then forward on to a simple and friendly user-facing page. The error information, including the exception thrown, is available as container-created request attributes.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Another suggestion for you (if this works in your architecture)...

At work i've coded my error pages to be 'friendly' to everyone, and for anyone with an IP address that begins 10.0.0.*, I also output the stacktrace.

All of us at work are inside the firewall, and so we all have IP's that start with 10.0.0.*

This works only while a developer is inside the building, but then, that's where we'd want the stacktrace showing up. Whilst our customers and sales people... if they get a problem, it only shows the 'nice' page.
Lou Pelagalli
Ranch Hand

Joined: Nov 11, 2003
Posts: 150
    
    1
Bear and Mike,

I found an excellent solution. I think it's along the lines of what Bear suggested.

http://www.onjava.com/pub/a/onjava/2002/10/30/jakarta.html

Scroll down to Customizing the Exception Handler.

Thanks,

Lou
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

That is a great solution... if you're using Struts.
 
wood burning stoves
 
subject: Custom error-page tag drops useful console messages