gpt4 book ai didi

java - 如何访问位于jar的 'META-INF/resources'文件夹中的jsp页面中的Exception对象?

转载 作者:行者123 更新时间:2023-12-01 12:58:03 25 4
gpt4 key购买 nike

我想将 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 and errorPage 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 and isErrorPage attribute. This makes the un-handled exception available in a variable called exception.

如果您需要隐式异常对象,请勿手动重定向/转发到错误页面。

<小时/>

当您手动重定向到 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com