I've created exception handling in my Spring application using spring SimpleMappingExceptionResolver. Everything works fine. Now I need to somehow print the caught exception within the jsp page. Something like message and stack trace. In my jsp I've found the exception object in "exception" attribute. All I need to do is something like that:
${exception.printStackTrace()}
But I don't know how. Is there any way how to do that?:-)
Thanks for any suggestion,
Mateo
The printStackTrace() method of Java. lang. Throwable class used to print this Throwable along with other details like class name and line number where the exception occurred means its backtrace. This method prints a stack trace for this Throwable object on the standard error output stream.
To create a JSP error page, we need to set page directive attribute isErrorPage value to true, then we can access exception jsp implicit object in the JSP and use it to send customized error message to the client.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With