Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setting error page

Status
Not open for further replies.

samit700

Programmer
Sep 23, 2003
52
US
Hi all,
I am trying to set my error page for my application. This is what I have in the web.xml file:
<error-page>
<error-code>500</error-code>
<location>/error.jsp</location>
</error-page>

But whenever a server 500 internal error occurs, Tomcat still displays its own built in error page. How do I override that property to show my error page. My main reason of having my own error page is not to show exceptions to clients but just an error message.

Any help appreciated.

Thanks, Samit
 
Hi Sed,

Thanks for your reply. I tried using that page error directive for all my pages, but even that it didn't work. I am purposely throwing an exception from my program but Tomcat keeps bringing up its own error page. It seems there is some property in Tomcat that needs to be overriden.

Thanks,
Samit
 
Hi,

Do you have any suggestion of what might be going wrong ?

Now I am using global exception handling in Struts to forward to the error.jsp page when any of the exceptions occur. But in case there is a JSPException (while parsing JSP) or some other internal exception, this won't work.

Samit
 
The error tag in web.xml works when the error page is error.html and not error.jsp .

but I need to log exceptions to a log file which i cannot do in a jsp page.

huh ...
 
quick and dirty hack for that - have a "fake" .html error page so tomcat uses it - then forward that to a "real" error page to log the error and display the friendly messgage to the user :
Code:
<!-- my dummy errorpage.html -->
<html>
<head>
<script langauge="javascript">
function logerror() {
  document.location='logerror.jsp';
}
</script>
</head>
<body onload="error()">
</body>
</html>
Code:
<!-- my real logerror.jsp file -->
<html>

<body>
	This is the real error page the users will see
        so we can fake for tomcat the html/jsp problem
        <%
           // Do some logging stuff
        %>
</body>
</html>

--------------------------------------------------
Free Database Connection Pooling Software
 
oops :

<body onload="error()">

should be :

<body onload="logerror()">

--------------------------------------------------
Free Database Connection Pooling Software
 
Thanks for your reply again. Nice trick ... but how do I reference the exception/error that was raised as I need to log that in logerror.jsp?
 
I think you should be able to use JSP for your error page provided there is directive isErrorPage="true" in the error JSP page.
e.g.


Code:
<%@ page language="java" isErrorPage="true" %>

<head><title>ERROR!</title></head>
<body>
An Error has occurred: 
<br /><br />
<pre>
<% 
  if (exception != null) { 
     exception.printStackTrace(new java.io.PrintWriter(out));
  } 
%> 
</pre>
</body>
 
I am not sure where the error info is stored. When you throw an exception from your classes and don't handle it anywhere, then it is finally caught by servlet container (Tomcat) which redirects to error.html.

In general, what is the best way to log exceptions/errors that are not handled in the program. There should be some kind of filter provided by the container that allows us to log that exception and then display the error page. Otherwise I will have to catch the exception in the program, log it and again throw it up

Samit
 
The implicit 'exception' object should be the reference to the exception being thrown.
 
The implicit exception object is only defined if the exception occurs during the processing of the JSP page, so the control can be trasferred to the error page using errorPage and isErrorPage page directives.

In my case, the exception occurs in the bean or servlet and is finally caught by the servlet container. The servlet container then invokes the error page as configured in web.xml file using the <error> tag. Now how do I reference the error that occured which caused this page.

Any ideas !!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top