异常不打印NullPointerException的堆栈跟踪

时间:2014-08-29 15:54:56

标签: java exception nullpointerexception scriptlet

我的错误页面如下所示:

<div class="hideShow" style="width:99%; text-align: center;  display: none;" >
            <UL><LI> <strong><%=exception%> </strong></LI></UL>
</div> 

和我的scriptlet

<%
  ByteArrayOutputStream bytes = new ByteArrayOutputStream();
  PrintWriter writer = new PrintWriter(bytes, true);
  exception.printStackTrace(writer);
  exception.printStackTrace(System.err);
%>

所以在UI中我看到NUllPointerException但是我的控制台显示了整个堆栈跟踪。 我怎样才能在UI中看到整个堆栈跟踪。

我使用了下面的scriplet代码,

<div class="hideShow" style="width:99%; text-align: center;  display: none;" >
            <UL><LI> <strong><%=exception.printStackTrace(writer)%> </strong></LI></UL>
</div> 

但我在控制台中收到此错误:

The method print(boolean) in the type JspWriter is not applicable for the arguments (void)

有关如何显示我在控制台中看到的空指针的堆栈跟踪的任何建议。 它适用于其他类型的异常。

1 个答案:

答案 0 :(得分:1)

exception.printStackTrace(writer)没有返回值,因此无法将其打印到out

更改代码

<div class="hideShow" style="width:99%; text-align: center;  display: none;" >
            <UL><LI> <strong><%exception.printStackTrace(response.getWriter());%> </strong></LI></UL>
</div> 
相关问题