• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to transport the stacktrace of an Exception from a Action to a Error-JSP?

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi in my Action-Class
I create this exception und want to write them out in my
error.jsp.
I just get the message text in the properties
but not the stacktrace!
How can you get the stacktrace to the jsp?
Thanks a lot

try
{
int x = 3/0;
}


catch (ArithmeticException e)
{

ActionErrors errors = new ActionErrors();
errors.add("Error", new ActionError("title.error", e.getMessage()));

this.saveErrors(request,errors);

return (mapping.findForward("error"));
}



<%@ page contentType = "text/html;charset=UTF-8" language = "java"%>
<%@ taglib uri = "/WEB-INF/struts-logic.tld" prefix = "logic"%>
<%@ taglib uri = "/WEB-INF/struts-html.tld" prefix = "html"%>
<%@ taglib uri = "/WEB-INF/struts-bean.tld" prefix = "bean"%>
<%@ page import = "org.apache.struts.action.Action"%>
<%@ page import = "org.apache.struts.action.ActionErrors"%>
<logic:messagesPresent>
<table class = "error">
<html:messages id = "error">
<tr>
<td>
<ul>
<li class="error"><bean:write name = "error"/></li>
</ul>
</td>
</tr>
</html:messages>
</table>
</logic:messagesPresent>
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The toString() method of exception includes a stack trace, so here's one way you could do it:

in your ApplicationResources.properties file, code:
title.error=The following error occurred: {0} Here is the full message with stack trace: {1}

Then in your Action class, code:

new ActionError("title.error", e.getMessage(), e.toString()
 
starki fox
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This gives us a little bit more information:

StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
String stacktrace = sw.toString();

ActionErrors errors = new ActionErrors();
errors.add("test",new ActionError("title.error", e.getMessage(), stacktrace));

Thank you!
 
reply
    Bookmark Topic Watch Topic
  • New Topic