wood burning stoves*
The moose likes JSP and the fly likes Printing Stacktrace in error jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "Printing Stacktrace in error jsp" Watch "Printing Stacktrace in error jsp" New topic
Author

Printing Stacktrace in error jsp

rudresh kumar
Ranch Hand

Joined: Jan 04, 2006
Posts: 83
Hi all,

Can anyone help me on showing stacktrace in error jsp.

Thanks in advance
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30586
    
154

On the error page, just do:
exception.printStackTrace()

Although this begs the question: what is a user going to do with an exception. Why not write the exception to the error log so it is persisted and you can go back to it after a user complains?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
sudhir nim
Ranch Hand

Joined: Aug 29, 2007
Posts: 212

exception.printStackTrace() will print stack trace on console not on jsp page.
If you want to display stack trace on jsp page use following line.

exception.printStackTrace(response.getWriter());


[Servlet tutorial] [Servlet 3.0 Cook Book]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
And you may want to go to a bit more trouble yet to replace newlines with <br> and such. It might be entertaining to write a PrintStream implementation that does that.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Stan James:
And you may want to go to a bit more trouble yet to replace newlines with <br> and such. It might be entertaining to write a PrintStream implementation that does that.


Or wrap the call in a set of <pre></pre> tags.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Rodrigo Tomita
Ranch Hand

Joined: Apr 28, 2008
Posts: 70
I know this is a fairly old thread, but just wanted to share what I could put together from the info presented here. We defined a default error page and put the stack trace "hidden" from the user. In dev/test environments, we can right-click the page and show the source code to see the stack trace.

<blockquote>code:
<pre name="code" class="core">
<%@ page isErrorPage="true" import="java.io.*"%>

<div id="stacktrace" style="display:none;">
<pre>
<%
// if there is an exception
if (exception != null) {
// print the stack trace hidden in the HTML source code for debug
exception.printStackTrace(new PrintWriter(out));
}
%>
</pre>
</div>
</pre>
</blockquote>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Printing Stacktrace in error jsp