Do you use JUnit? I took a look at the JUnit source to see how it displays a stack trace in a JTextArea (in the SwingUI version). BaseTestRunner.getFilteredTrace is the workhorse method:
Since there's a version of printStackTrace that takes PrintWriter, they wrap a StringWriter with a PrintWriter, then pass it into printStackTrace. Then they build a String out of the StringWriter (using an intermediate StringBuffer -- I'm not clear on why they didn't just do String trace = stringWriter.toString()). Anyhow, this is one way to do this. (Shamelessly stolen...) Here's a less verbose version:
[ July 01, 2002: Message edited by: Michael Matola ]
Joined: Mar 25, 2001
But wait, you said "page." Are you working with servlets? If so, don't even bother with the String and StringWriter, just call printStackTrace with you PrintWriter instance from HttpServletResponse as a parameter.
Sorry, don't know much about JSP. Take a look at this thread in the JSP forum. The poster seems to have the same question and has pretty much come up with the same solution. (I'm not clear where the "out" object is coming from in that example.)
Joined: May 03, 2002
Thanks your solution worked out great.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com