stacktTrace in JSP
Hi
I am using the implicit object "exception" in a JSP error page.
I am trying to pass the complete stack trace of this exception through a
<%=exception%> which does not work..
I cant use the getStackTrace() method here because it returns void and
getMessage() is returning null. So if someone knows how I can do this.. it will be really nice. Thank you very much
regards
[424 byte] By [
mayamohana] at [2007-11-27 1:21:11]

# 4
[nobr]Ok, what you want to do is print out the stack trace onto the error page?
I'm going from memory here, and don't have time to test it, but it might push you in the right direction.
I vaguely recall doing something like this at some point on an error page:
<br>
<pre>
<%
exception.printStackTrace(new java.io.PrintWriter(out))
%>
</pre>
<br>
It uses the implicit variables exceptions and out.
You need <pre> tags for it to be formatted in a readable fashion.
Hope this helps,
evnafets[/nobr]
# 5
Thanks for the help.. well.. but not really what I was looking for..
I want to pass the value of the stack trace as a form field.. or a query string .. or anything to a different page.. .. in my case.. i am passing it to an email using mailto link... which doesnt matter..
So, I was trying <%= exception%>, which just shows the name of the exception. I cannot use <%=exception.printStackTrace() %> because it returns void..
Well thats it.
# 6
It doesn't matter that it returns void. Use the suggestion as evnafets mentioned. Write it to a [url=http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Throwable.html#printStackTrace(java.io.PrintStream)]PrintStream or PrintWriter[/url].
CharArrayWriter trace = new CharArrayWriter();
e.printStackTrace(new PrintWriter(trace));
// mail it.
...
message.setContent(trace.toString(), "text/plain");