This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
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 ]
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.)