You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Konrad Bernstein <be...@gmx.net> on 2005/06/06 08:41:08 UTC

pageContext.getException() always null

Hi,
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 within
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());
%>
   
<HTML>
  <HEAD>
    <title>Error</title>
  </HEAD>
  <body>
   <H1>Error occured</H1>
   <custom:errortag/>
  </body>
</html>


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
exception.
exPage = null
pageContext has null exception

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

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,
Konrad

-- 
Geschenkt: 3 Monate GMX ProMail gratis + 3 Ausgaben stern gratis
++ Jetzt anmelden & testen ++ http://www.gmx.net/de/go/promail ++

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: pageContext.getException() always null

Posted by Mark Thomas <ma...@apache.org>.
Konrad Bernstein wrote:
> However, looks like a TC bug to me, that only occurs if you setup your
> error pages by
> the error-tag within web.xml (not by using the page directive
> errorPage). pageContext.getException()
> only returns what is saved under attribute
> "javax.servlet.jsp.jspException". But this attribute is
> not set, if you're throwing from a Servlet, for instance (as with Struts
> etc.).

This is http://issues.apache.org/bugzilla/show_bug.cgi?id=31659 and is 
fixed in 5.5.9+

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: pageContext.getException() always null

Posted by Konrad Bernstein <be...@gmx.net>.
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: pageContext.getException() always returns null.

I then built Tomcat on my own (via
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/build.xml)
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 JspRuntimeLibrary.getThrowable(request) instead of
request.getAttribute(PageContext.EXCEPTION)

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

So, if you use code like

Throwable error = (Throwable)
request.getAttribute("javax.servlet.error.exception")
instead of
pageContext.getException()

you should be fine.

However, looks like a TC bug to me, that only occurs if you setup your
error pages by
the error-tag within web.xml (not by using the page directive
errorPage). pageContext.getException()
only returns what is saved under attribute
"javax.servlet.jsp.jspException". But this attribute is
not set, if you're throwing from a Servlet, for instance (as with Struts
etc.).

Have fun,
Konrad

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org