如何在 JSP 页面中打印错误堆栈跟踪? [英] How can I print error stack trace in JSP page?

查看:42
本文介绍了如何在 JSP 页面中打印错误堆栈跟踪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 web.xml 中设置了这样的错误页面:

I have set my error page like this in web.xml:

 <error-page>
  <exception-type>java.lang.Exception</exception-type>
  <location>/errors/error.jsp</location>
 </error-page>

现在我想在 JSP 上打印错误堆栈跟踪(当然仅在开发模式下).如何在 JSP 页面上打印错误堆栈跟踪?我没有为此应用程序使用任何框架,因此只有默认的 servlet API 可用于我的程序.

Now I would like to print stack trace of error on JSP (of course in development mode only). How can I print stack trace of error on my JSP page? I don't use any frameworks for this application, so only default servlet APIs are available for my program.

推荐答案

从内部设置的请求中获取参数,并用它来打印和处理其他信息,如causemessage

get the parameter from request that is set internally and use it to print and deal with other information like cause, message

<c:set var="exception" value="${requestScope['javax.servlet.error.exception']}"/>

并打印堆栈跟踪

<!-- Stack trace -->
<jsp:scriptlet>
  exception.printStackTrace(new java.io.PrintWriter(out));
</jsp:scriptlet>

<小时>

另见

这篇关于如何在 JSP 页面中打印错误堆栈跟踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆