Hi, I have just submitted #3377 to Bugzilla, where I describe the following problem and a workaround. When using the error-page directive in web.xml, the exception handling of JSP pages is insufficient. What happens is that Jasper catches the exception, but isn't aware of the configured error-page. As it may throw only ServletExceptions, it does exactly that, discards the actual exception, keeps the exception message and creates a new ServletException. (See handlePageException().) In practice that means, that the stack trace is lost in error messages, making them practically useless, because you always see the stack trace of handlePageException(). IMO Jasper should have a possibility to see the error-page directive and handle it properly. In our production environment we do this with the attached patch, which is mainly a workaround, because it breaks the separation between TomCat and Jasper. However, as the Specification does not give a way to find the configured error-page (at least no way that I can think of), this is probably the way to go. Thanks, Jochen
Only in c:\Programme\jakarta-tomcat-3.2.3\src/org/apache/jasper/runtime: .nbattrs diff -ubr --exclude *.class --exclude *~ c:\temp\jakarta-tomcat-3.2.3\src/org/apache/jasper/runtime/PageContextImpl.java c:\Programme\jakarta-tomcat-3.2.3\src/org/apache/jasper/runtime/PageContextImpl.java --- c:\temp\jakarta-tomcat-3.2.3\src/org/apache/jasper/runtime/PageContextImpl.java Tue Jul 17 16:57:50 2001 +++ +c:\Programme\jakarta-tomcat-3.2.3\src/org/apache/jasper/runtime/PageContextImpl.java + Mon Sep 3 08:21:17 2001 @@ -441,11 +441,34 @@ // set the request attribute with the exception. request.setAttribute("javax.servlet.jsp.jspException", e); - if (errorPageURL != null && !errorPageURL.equals("")) { + // Try to obtain an error page URL + String url = errorPageURL; + if (url == null || "".equals(url)) { + org.apache.tomcat.core.Context ctx = null; + if (context instanceof org.apache.tomcat.core.Context) { + ctx = (org.apache.tomcat.core.Context) context; + } else if (context instanceof +org.apache.tomcat.facade.ServletContextFacade) { + ctx = ((org.apache.tomcat.facade.ServletContextFacade) +context).getRealContext(); + } + if (ctx != null) { + url = ctx.getErrorPage(e.getClass().getName()); + if (url == null || "".equals(url)) { + url = ctx.getErrorPage("java.lang.Exception"); + if (url == null || "".equals(url)) { + url = ctx.getErrorPage("java.lang.Throwable"); + if (url == null || "".equals(url)) { + url = ctx.getErrorPage("500"); + } + } + } + } + } + + if (url != null && !"".equals(url)) { try { - forward(errorPageURL); + forward(url); } catch (IllegalStateException ise) { - include(errorPageURL); + include(url); } } // Otherwise throw the exception wrapped inside a ServletException. else { diff -ubr --exclude *.class --exclude *~ c:\temp\jakarta-tomcat-3.2.3\src/org/apache/tomcat/facade/ServletContextFacade.java c:\Programme\jakarta-tomcat-3.2.3\src/org/apache/tomcat/facade/ServletContextFacade.java --- c:\temp\jakarta-tomcat-3.2.3\src/org/apache/tomcat/facade/ServletContextFacade.java Tue Jul 17 16:57:50 2001 +++ +c:\Programme\jakarta-tomcat-3.2.3\src/org/apache/tomcat/facade/ServletContextFacade.java + Mon Sep 3 08:21:38 2001 @@ -79,7 +79,7 @@ * @author James Todd [[EMAIL PROTECTED]] * @author Harish Prabandham */ -final class ServletContextFacade implements ServletContext { +public final class ServletContextFacade implements ServletContext { // Use the strings from core private static StringManager sm = StringManager.getManager("org.apache.tomcat.core"); private ContextManager contextM; @@ -90,7 +90,7 @@ this.context = context; } - Context getRealContext() { + public Context getRealContext() { return context; }