1

I am using servelets to design my appliction . Can any one suggest me how to write the Exception message in output page ? example if I any sql exception is thrown I want to diplay the printStackTrace() method message in output page(i.e can be html or jsp) The following is the code .

exceptionObject.printStackTrace();

Regards, Raj

2

2 Answers 2

2

In jsp there is standard way of handling exception, instead of filling the output page with exception you should consider displaying the error page.

In jsp you mark an error page by setting error directive

<%@ page isErrorPage='true' %>

Once done you have the implicit object exception with you use it to display the stacktrace or whatever you want to do.

Sign up to request clarification or add additional context in comments.

Comments

0

How can I convert a stack trace to a string?:

StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
t.printStackTrace(pw);
sw.toString(); // stack trace as a string

For output use:

<%= sw.toString() %>

Or check: How can I print error stack trace in JSP page?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.