Error Page - how to print stack trace in JSP

后端 未结 2 1805
梦谈多话
梦谈多话 2021-01-04 23:16

I\'ve created exception handling in my Spring application using spring SimpleMappingExceptionResolver. Everything works fine. Now I need to somehow print the caught exceptio

相关标签:
2条回答
  • 2021-01-04 23:52

    Had to do this (dev/local environment only) in pages in the past and just want to display it in a textarea or a preformatted block. The output from skaffman prints out each strack trace element but not the message and exception class.

    If you want it pre-formatted as per a printStackTrace() consider using Spring EL and commons-lang3.

    <spring:eval expression="T(org.apache.commons.lang3.exception.ExceptionUtils).getStackTrace(exception)"/>
    
    0 讨论(0)
  • 2021-01-05 00:04

    The easiest solution I can think of is to loop over the stack trace elements, taking advantage of the Throwable.getStackTrace() method:

    <c:forEach items="${exception.stackTrace}" var="element">
        <c:out value="${element}" />
    </c:forEach>
    

    You'd need to add some formatting, of course.

    0 讨论(0)
提交回复
热议问题