在Interceptor.intercept()内部,我如何知道Action是否已经被执行?
我正在使用拦截器在基于 Struts 的应用程序中实现一些内容,但我对它们的生命周期如何工作感到困惑。根据Struts文档(“拦截器”,"编写拦截器" 和 "Big picture"),它应该像这样工作:
FirstInterceptor NextInterceptor LastInterceptor Action Result LastInterceptor NextInterceptor FirstInterceptor
这是有道理的,但我正在绊倒如何区分在操作之前执行的拦截器调用和在结果呈现之后执行的拦截器调用(我在这里跳过 PreResultListener )。 如果我启动调试器,我会收到两次对 intercept()
的调用,并且在我正在传递的 ActionIn Vocation
上找不到任何太明显的内容。< /strike> (更新:这部分对我来说是一个很大的困惑,一旦我得到它,我就能够回答下面的问题)
"Big picture" 页面谈论了一些令人困惑的“之前”和“之后”被称为“子句”,但我不知道该怎么做:
[...]
这包括在调用操作本身之前调用任何拦截器(before 子句)。
[...]
再次执行拦截器(以相反的顺序,调用 after 子句)。
[...]
(更新:但这两个句子仍然很糟糕)
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 ("Interceptors", "Writing interceptors" and "Big picture"), it should work something like this:
FirstInterceptor NextInterceptor LastInterceptor Action Result LastInterceptor NextInterceptor FirstInterceptor
which makes sense, but I'm stumbling on how to distinguish an interceptor call executing before the action from one executing after the result is rendered (I'm skipping PreResultListener
s here). If I fire up a debugger, I get two calls to (Update: This part was a major confusion on my end, and I was able to answer my question below once I got it)intercept()
and can't find anything too obvious on the ActionInvocation
I'm being passed.
The "Big picture" page talks somewhat confusingly of a "before" and "after" "clause" that are called, but I don't know what to make of it:
[...]
This includes invoking any Interceptors (the before clause) in advance of invoking the Action itself.
[...]
Interceptors are executed again (in reverse order, calling the after clause).
[...]
(Update: These two sentences are still bad, though)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有对拦截器的两次调用:
(请注意,我在调试器中看到的“两次拦截调用”是我没有注意到的不太明显的重定向的结果。这让我很困惑。)
There's no two calls to the interceptor:
(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.)