论坛首页 Java企业应用论坛

webwork中如何截获Action抛出的异常

浏览 5164 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2005-04-07  
想专门做异常处理,至少也是过滤信息。
但是用Filter, 得到response内容都是空

谢谢。
   发表时间:2005-04-07  
我觉得可以自己写一个servletdispatcher,继承webwork2自带的那个。
0 请登录后投票
   发表时间:2005-04-08  
用webwork的interceptor实现了。
0 请登录后投票
   发表时间:2005-04-08  
很有必要吗?出了错转到error不久得了
0 请登录后投票
   发表时间:2005-04-08  
不妨参考jert的做法,用一个拦截器。
0 请登录后投票
   发表时间:2005-04-10  
jert拦截器
0 请登录后投票
   发表时间:2005-04-13  
public class ExceptionInterceptor implements Interceptor {
    private static Logger log = Logger.getLogger(ExceptionInterceptor.class);
    public static final String EXCEPTION = "exception";

    public String intercept(ActionInvocation invocation) throws Exception {
        try {
            return invocation.invoke();
        } catch (Exception e) {
            String message = "Caught exception while invoking action: " + invocation.getAction();

            log.error(message, e);

            StringWriter sw = new StringWriter();

            e.printStackTrace(new PrintWriter(sw));
            invocation.getInvocationContext().put("_exception_message_", e.getMessage());
            invocation.getInvocationContext().put("_exception_more_detail_", sw.toString());

            return EXCEPTION;
        }
    }

    public void destroy() {
    }

    public void init() {
    }
}
0 请登录后投票
   发表时间:2005-04-27  
谢谢兄弟。只是,这个。。。。我不是很明白啊,呵呵。

就是我现在有个interceptor 了,现在我要做的是:
再加你这个interceptor? 这样的话,新的interceptor 能catch到就的interceptor的exception 吗?

还是说,现在我的interceptor 按照你的interceptor 的结构,做些修改?

-----------------------------

还有, 我按照你的结构,修改我的interceptor。如下:
.........
invocation.getInvocationContext().put("_exception_message_", e.getMessage());
invocation.getInvocationContext().put("_exception_more_detail_", sw.toString());
return EXCEPTION;
能成功地dispatch到知道的页面, 但是jsp页面如何取出"_exception_message_"的数据啊?
我用<ww:property value="_exception_message_" />不行啊。。
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics