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

标签 java jsp jar

我想将 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/

相关文章:

java - 如何在android中动态设置布局

java - 从数组创建的字符串不断返回 null

java - TLD、标签库和属性设置方法有问题

java - 是否可以在 Spring Boot 中的两个方法之间传递模型值?

java - 如何将外部库添加到 Hadoop map-reduce 任务

java - Maven 默认分隔符

java - 通过传递引用与返回引用来反序列化对象

动态 Web 项目中的 Eclipse Juno 没有 JSP(但其他一切都很好)

java - 在工件对话框中找不到 "Create Manifest"按钮

java - 重构树的递归修改