Reputation: 4477
My spring-mvc web application has an error page with a collapsible stack trace element in it (obviously a development/debug option). This used to work just fine, and displayed the proper stack trace from the controller (or sometimes from the JSP engine).
Q: Is it possible to have a JSP be an error page, or should it be static HTML?
Q: What am I doing wrong?
The chain of events is (I think) driven by an error handler defined in my web.xml:
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/view/errors/internalError.jsp</location>
</error-page>
Somewhere along the way (switched to a maven build system, upgraded jetty, and spring 2.5 -> 3.0), I noticed that this error page stopped working the way it had been. It renderes the same with one problem -- the exception stack-trace displayed is NOT from the exception thrown in the controller, but from the error page itself!
javax.servlet.ServletException: javax.servlet.jsp.JspTagException:
500 /WEB-INF/jsp/admin/errors/internalError.jsp
at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
at org.apache.jsp.WEB_002dINF.jsp.admin.defaultParent_jsp._jspService(defaultParent_jsp.java:225)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
What seems to be happening here, is the following chain of events:
throw new RuntimeException("no bananas")
The JSP engine seems to die when rendering the default parent JSP -- it seems to run into trouble in: org.apache.taglibs.standard.tag.common.core.ImportSupport
. I've seen some web posts where people say it has to do with the import being from a WEB-INF directory.
// disallow inappropriate response codes per JSTL spec
if (irw.getStatus() < 200 || irw.getStatus() > 299) {
throw new JspTagException(irw.getStatus() + " " + stripSession(targetUrl));
}
Though it looks here like any HTTP 500 error would break it. But is that not what error the page should have?
Upvotes: 2
Views: 3379
Reputation: 1108577
Q: Is it possible to have a JSP be an error page, or should it be static HTML?
It's perfectly fine. It can even be a servlet or something. As long as it doesn't have bugs of course.
Q: What am I doing wrong?
Your error page has a bug. You're apparently using <c:import>
inside the error page to include a fragment from /WEB-INF
. This is disallowed because it's not a public resource (honestly I don't recall that it would ever have worked in ancient JSTL versions). Rather use <jsp:include>
.
Upvotes: 2