wood burning stoves
The moose likes JSP and the fly likes pageContext.getException() always null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "pageContext.getException() always null" Watch "pageContext.getException() always null" New topic

pageContext.getException() always null

Konrad Bernstein

Joined: Jun 06, 2005
Posts: 2
I have a rather strange problem with handling an exception within a custom
jsp tag.

The problem is, that pageContext.getException() always returns null.
This is the case within the tag's code, but also witin a Scriptlet inside
the JSP.
However, the variable 'exception' itself is properly set.

My error.jsp looks like this:
<%@page isErrorPage="true" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

System.out.println("Exception = " + exception);
System.out.println("exPage = " + pageContext.getException());

<H1>Error occured</H1>

The tag class has code like this:

private Exception getTerribleException() {

if (pageContext.getException() == null) {
System.out.println("pageContext has null exception");
return null;

Well, the output is as mentioned above: only the variable 'exception' within
the JSP can be successfully accessed. Retrieving the exception from the
pageContext always returns null.

Exception = javax.servlet.ServletException: This is my self thrown
exPage = null
pageContext has null exception

The error page is comming up by tomcat through the <error-page>
entry in web.xml:


As far as I know, for all error pages (<%@page isErrorPage="true" %> ,
the counterpart for the implicit variable 'exception' of a JSP is

However, something seems to go wrong.
I'm using JBoss 3.2.26 with integrated Tomcat. I also tried tomcat
standalone (5.0.18), same result.

Help greatly appreciated,
leon fan

Joined: Aug 02, 2004
Posts: 19
the pageContext.getException() work on my Sun web server very well. as following, I can get error information on my web page when an exception occur.

<TITLE>Error Page</TITLE>
<%@ page isErrorPage="true" %>
<%@ page import="java.io.*" %>
Error Computing Speed</TABLE>
ComputeSpeed.jsp reported the following error:
<I><%= exception %></I>. This problem occurred in the
following place:
<% out.println("exPage=" + pageContext.getException()); %>
Konrad Bernstein

Joined: Jun 06, 2005
Posts: 2
Seems to me like a pure Tomcat-issue.
Downloaded and tested a couple of TC versions (5.0.28, 5.0.30 beta).
Same result: always returns null.

I then built Tomcat on my own (via Tomcat-5.0-Build-Script and everything worked fine there.

Looking at the source of class PageContextImpl made clear, that
the version has changed. The new implementation of method getException()
now uses instead of

This comes down to returning the request attribute
"javax.servlet.error.exception" instead of

So, if you use code like

instead of

you should be fine.

However, looks like a TC bug to me.

Have fun,
I agree. Here's the link: http://aspose.com/file-tools
subject: pageContext.getException() always null
jQuery in Action, 3rd edition