Inside Interceptor.intercept(), how do I know if the Action has already been executed?

前端 未结 1 1926
醉话见心
醉话见心 2021-01-22 01:54

I\'m implementing some stuff in my Struts-based application using interceptors, and I\'m getting confused about how their lifecycle works. According to the Struts docs ("In

相关标签:
1条回答
  • 2021-01-22 02:58

    There's no two calls to the interceptor:

    public class MyInterceptor implements Interceptor {
    
        public String intercept(ActionInvocation invocation) {
            /*
            This is before Action.execute(),
            and before all interceptors down the stack
            */
    
            String code = invocation.invoke();
    
            /*
            This is after Action.execute(),
            the result rendering and all
            interceptors down the stack,
            but before the interceptors
            higher up in the stack.
            */
    
            return code;
        }
    
    }
    

    (Note that the "two calls to intercept" I was witnessing in the debugger were a result of a less obvious redirect that I failed to notice. This confused me a lot.)

    0 讨论(0)
提交回复
热议问题