File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printing Stacktrace in error jsp

 
rudresh kumar
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Can anyone help me on showing stacktrace in error jsp.

Thanks in advance
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33694
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
sudhir nim
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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());
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rodrigo Tomita
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic