我正在使用拦截器在基于 Struts 的应用程序中实现一些内容,但我对它们的生命周期如何工作感到困惑。根据 Struts 文档(“拦截者”, “编写拦截器” and “大图景”),它应该像这样工作:
FirstInterceptor
NextInterceptor
LastInterceptor
Action
Result
LastInterceptor
NextInterceptor
FirstInterceptor
这是有道理的,但我在如何区分在操作之前执行的拦截器调用和在结果呈现之后执行的拦截器调用时遇到了困难(我正在跳过PreResultListener
在这里)。 如果我启动调试器,我会收到两次调用intercept()
并且在上面找不到任何太明显的东西ActionInvocation
我被超越了。(Update:这部分对我来说是一个很大的困惑,一旦我得到它,我就能够回答下面的问题)
The “大图景”页面谈论了一些令人困惑的“之前”和“之后”“子句”,但我不知道如何理解它:
[...]
这包括在调用操作本身之前调用任何拦截器(before 子句)。
[...]
拦截器再次执行(以相反的顺序,调用 after 子句)。
[...]
(Update: 不过这两句话还是不好)
没有对拦截器的两次调用:
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;
}
}
(请注意,我在调试器中目睹的“两次拦截调用”是我没有注意到的不太明显的重定向的结果。这让我很困惑。)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)