Formatting a Java Traceback in a JSP

When a JSP gets an error resulting in a Traceback, it usually is a continuous jumble of lines. For example, the following JSP produces the traceback that is not formatted:

   <%@ page import="java.io.*" %>
<%
Exception exception = new Exception ("mistake");
exception.printStackTrace( new PrintWriter( out ) );
%>

It is actually even more unreadable as it appears in the Web Browser.

The way to fix this is with the <pre> tag, that tells the Browser to format it correctly. The JSP now looks like this

   <%@ page import="java.io.*" %>
<pre> <% Exception exception = new Exception ("mistake"); exception.printStackTrace( new PrintWriter( out ) ); %> </pre>