我想将 error.jsp 页面放置在 JAR 的 META-INF/resources 文件夹中,以便我的 Web 应用程序可以重定向到此常见错误页面。
虽然,我可以将应用程序重定向到此 error.jsp 页面,但该页面无法访问隐式 exception
对象,以便打印堆栈跟踪。
同时,exception
隐式对象是 null
在此页面中。
我已经添加了<%@ page isErrorPage="true"%>
error.jsp 中的标记。
是否有其他方法可以从此 jsp 页面访问 Exception 对象?
最佳答案
隐式异常对象如果 JSP 本身使用 jsp 中的以下代码或错误页面的 web.xml 中的设置自动调用它,则该对象将可用。
<%@page errorPage=”relativeURL/path of the error page” %>
如果手动重定向,隐式异常对象将不可用,因为它就像普通的 jsp 页面一样。
A JSP page specifies the error page with the
page
directive anderrorPage
attribute. When an unhanded exception occurs, any un-flushed output in the output stream is discarded and the error page is immediately executed.The error page indicates that it is an error page with the
page
directive andisErrorPage
attribute. This makes the un-handled exception available in a variable calledexception
.
如果您需要隐式异常对象,请勿手动重定向/转发到错误页面。
<小时/>当您手动重定向到 error.jsp 页面时。您已将异常设置为请求属性。
在重定向到 error.jsp 页面之前,只需在请求中设置一个属性
request.setAttribute("exception",exception); // You have to set it manually
并在error.jsp页面中检索。
request.getAttribute("exception");
<小时/>
注意:您可以尝试使用 JSTL 以及使用 c:set .
关于java - 如何访问位于jar的 'META-INF/resources'文件夹中的jsp页面中的Exception对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23737051/