| Author |
pageContext.getException() always null
|
Konrad Bernstein
Greenhorn
Joined: Jun 06, 2005
Posts: 2
|
|
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 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()); %> <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 The error page is comming up by tomcat through the <error-page> entry in web.xml: <error-page> <error-code>500</error-code> <location>/error.jsp</location> </error-page> 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
|
 |
leon fan
Greenhorn
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. <HTML> <HEAD> <TITLE>Error Page</TITLE> </HEAD> <BODY> <%@ page isErrorPage="true" %> <%@ page import="java.io.*" %> <TABLE BORDER=5 ALIGN="CENTER"> <TR><TH CLASS="TITLE"> Error Computing Speed</TABLE> <P> ComputeSpeed.jsp reported the following error: <I><%= exception %></I>. This problem occurred in the following place: <PRE> <% out.println("exPage=" + pageContext.getException()); %> </PRE> </BODY> </HTML>
|
 |
Konrad Bernstein
Greenhorn
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 "javax.servlet.jsp.jspException". So, if you use code like instead of you should be fine. However, looks like a TC bug to me. Have fun, Konrad
|
 |
 |
|
|
subject: pageContext.getException() always null
|
|
|