I've encountered a strange thing. I have configured exception handling in struts 2.1.8 like stated here, only that I redirect to an action instead to JSP (to send emails...).
So, in the action I have
ActionContext ac = ActionContext.getContext();
String stackTrace = null;
if(ac.getValueStack().findValue("exceptionStack") != null) {
stackTrace = ac.getValueStack().findValue("exceptionStack").toString();
} else {
stackTrace = "Stack trace not found!";
}
I had to make this if-else because sometimes the value is 开发者_如何转开发null. I haven't found the difference why sometimes I get the stack trace and sometimes I don't. All the errors happen in Struts2.
Did anyone had similar problem? Can anybody directs me where is the problem?
if you map exception with chain result type you'll keep the same request and so the same ValueStack.
First, ValueStack
is per-request (each thread has its own), so redirecting to a new action will cause you to lose any data you had in the previous request's ValueStack
.
With that said, what is your goal here? The link you provided explains how to map different types of exceptions to custom error pages (or results). Why doesn't that work for you? You mention you want to send emails -- are you sending an email notification about the actual exception (and stack trace)?
If you can expand a bit about what you are trying to do, then perhaps we can give you some guidance.
精彩评论