Error page - how to print stack trace in JSP

I created exception handling in my Spring application using Spring SimpleMappingExceptionResolver. Everything is working fine. Now I need to somehow print the caught exception on the jsp page. Something like message tracing and stack. In my jsp, I found an exception object in the "exception" attribute. All I need to do is something like this:

${exception.printStackTrace()} 

But I do not know how to do this. Is there any way to do this? :-)

Thanks for any suggestion,

Mateo

+8
spring exception
source share
2 answers

The easiest solution I can think of is looping over stack trace elements using the Throwable.getStackTrace() method:

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

Of course, you will need to add formatting.

+17
source share

You have to do this (only dev / local environment only) only on pages in the past and just wants to display them in a text field or in a pre-formatted block. The result from the scaffman displays each strack trace element, but is not a message or an exception class.

If you want it to be pre-formatted according to printStackTrace (), use Spring EL and commons-lang3.

 <spring:eval expression="T(org.apache.commons.lang3.exception.ExceptionUtils).getStackTrace(exception)"/> 
+2
source share

Source: https://habr.com/ru/post/650136/


All Articles