【问题标题】:Override an struts 2 interceptor覆盖一个struts 2拦截器
【发布时间】:2016-01-30 05:35:55
【问题描述】:

我们正在使用store 拦截器。在极少数情况下,此拦截器会抛出Session Already Invalidate 异常,同时尝试将错误消息放入会话中(MessageStoreInterceptor line: 282)。

我试图覆盖这个拦截器并默默地浅化异常,并让动作被执行。

这似乎很简单,但我找不到发生异常时应该返回什么(如何获得下一个拦截器?!):

public class MyMessageStoreInterceptor extends MessageStoreInterceptor {

    @Override
    public String intercept(ActionInvocation invocation) throws Exception {

        try{
            return super.intercept(invocation);
        }catch(IllegalStateException ex){
            return ??; 
        }

    }    
}

【问题讨论】:

    标签: java struts2 interceptor struts2-interceptors


    【解决方案1】:

    如果你想进入下一个拦截器,你应该返回invocation.invoke()。它返回一个动作结果。如果由于异常没有得到结果,并且想要继续操作调用,则应返回自己的结果或预定义结果之一,例如 SUCCESSERROR

    @Override
    public String intercept(ActionInvocation invocation) throws Exception {
    
        try{
            return super.intercept(invocation);
        }catch(IllegalStateException ex){
            return Action.ERROR; 
        }
    
    }    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-31
      • 2011-10-25
      • 1970-01-01
      • 2011-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多