• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Implicit variable "exception" is null

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am new to jsp/servlets and I came across the following problem (Tomcat 4.1.18 + Apache 2.0 + RedHat 8.0):
I would like all errors & exceptions to go to the following generic error page:
----------- /error-pages/error.jsp ---------
<%@ page isErrorPage="true" %>
<html>
<body>
Oops! We got an exception:<br>
<pre>
<%
if (exception != null)
out.print(exception.getMessage());
else
out.print("Just an error");
%>
</pre>
</body>
</html>
-------
So, in my web.xml file I added the following entry:
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error-pages/error.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/error-pages/error.jsp</location>
</error-page>
Now, when a servlet throws an exception (in fact, it re-throws any exception thrown inside it, by wrapping it into a ServletException) via
try{
// some code ...
}
catch(Exception e){
throw new ServletException(e);
}
the container correctly redirects to error.jsp . The problem is that the implicit variable "exception" that should be available to this page is null. Can anyone tell me why it is so? And is there any way to fix this and access the information about the thrown exception from the error page?
I have seen many postings with a problem similar to mine, but none of them seemed to have any resolutions.
Thanks a lot!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic