Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I print error stack trace in JSP page?

Tags:

I have set my error page like this in web.xml:

 <error-page>   <exception-type>java.lang.Exception</exception-type>   <location>/errors/error.jsp</location>  </error-page> 

Now I would like to print stack trace of error on JSP (of course in development mode only). How can I print stack trace of error on my JSP page? I don't use any frameworks for this application, so only default servlet APIs are available for my program.

like image 636
newbie Avatar asked Nov 15 '11 11:11

newbie


1 Answers

get the parameter from request that is set internally and use it to print and deal with other information like cause, message

<c:set var="exception" value="${requestScope['javax.servlet.error.exception']}"/> 

and to print stacktrace

<!-- Stack trace --> <jsp:scriptlet>   exception.printStackTrace(new java.io.PrintWriter(out)); </jsp:scriptlet> 

See Also

  • JSPIntro4 - Handling Errors
like image 119
jmj Avatar answered Sep 19 '22 00:09

jmj