Struts2错误处理-未找到异常堆栈
我遇到了一件奇怪的事情。我已经在 struts 2.1.8 中配置了异常处理,如此处所述,只是我重定向到一个操作而不是 JSP(发送电子邮件...)。
因此,在我执行的操作中,
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!";
}
我必须执行此 if-else,因为有时该值为 null。我还没有找到为什么有时我得到堆栈跟踪而有时却没有的区别。所有的错误都发生在Struts2中。
有人遇到过类似的问题吗?有人可以指导我问题出在哪里吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用链结果类型映射异常,您将保留相同的请求,因此也保留相同的 ValueStack。
if you map exception with chain result type you'll keep the same request and so the same ValueStack.
首先,
ValueStack
是针对每个请求的(每个线程都有自己的),因此重定向到新操作将导致您丢失在前一个请求的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'sValueStack
.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.