Saturday, March 14, 2009

How can I get to print the stacktrace for an exception occuring within my

Question :How can I get to print the stacktrace for an exception occuring within my
JSP page? (JSP)

Answer :By printing out the exception's stack trace, you can usually diagonse a
problem better when debugging JSP pages. By looking at a stack trace, a
programmer should be able to discern which method threw the exception
and which method called that method. However, you cannot print the
stacktrace using the JSP out implicit variable, which is of type JspWriter.
You will have to use a PrintWriter object instead. The following snippet
demonstrates how you can print a stacktrace from within a JSP error page:
<%@ page isErrorPage="true" %>
<%
out.println("
");
PrintWriter pw = response.getWriter();
exception.printStackTrace(pw);
out.println("
");
%>

No comments: