拦截器和过滤器之间的区别 - 这是对的吗? [英] Difference between Interceptors and Filters - Is this right?
问题描述
我正在研究这个,以便我可以在面试中做出更好的反应.我一直在寻找一个清晰简洁的答案.
I'm researching this so that I can respond better in interviews. I've been searching around for a clear and concise answer.
到目前为止,如果我错了或缺乏细节,请务必纠正我:
So far, and by all means correct me if I am wrong or lacking in detail:
- 过滤器是 Servlet API 的一部分,拦截器是 Struts 2.(虽然看起来很明显)
- 拦截器堆栈会触发配置包中的请求,而过滤器仅适用于它们映射的 URL.
- 拦截器可以通过 excludeMethods 和 includeMethods 配置为执行或不执行取决于特定的目标操作方法,而过滤器缺少此功能.
- 过滤器是拦截过滤器模式的实现,而拦截器是拦截器模式的实现.
这看起来像是一个准确而完整的答案吗?我应该添加或更正任何内容吗?线程问题/差异如何?
Does this seem like an accurate and complete answer? Should I add or correct anything? What about threading issues / differences?
推荐答案
我认为第一点是答案,但你应该能说的不仅仅是
I think the first point is the answer, but you should probably be able to say more than just
拦截器在 struts 2 中,过滤器是 Servlet API 的一部分
interceptors are in struts 2 and filters are part of the Servlet API
事实上,作为一名面试官,我期待并希望您在这里准确解释 Servelt API 和 Web 应用程序框架(如 Struts 2)之间的区别.这实际上是一个展示您对整个 Java Web 应用程序生态系统和基础架构的理解的机会.
In fact, as an interviewer, I would be expecting and hoping to here you explain exactly what the difference between the Servelt API and a web application framework, like Struts 2 is. This is actually a chance to show your understanding of the entire Java web app ecosystem and infrastructure.
好的答案可能涉及:
Struts 2 框架是如何在 Servlet 过滤器中实现的.
How the Struts 2 framework is implemented within a Servlet Filter.
哪些特定用例会调用外部的 servlet 过滤器struts 2 但在同一个 Web 应用程序中?
What specific use cases would call for a servlet filter outside of struts 2 but within the same web application?
Servlet API 到底是什么,一个网络应用程序,一个网络应用程序框架等?
What indeed is the Servlet API, a web application, a web application framework, etc.?
我想,以显示您对所有这些主题的理解的方式回答正是那里要找的.
Answering in way that showed your understanding of all of these topics is what there looking for, I would guess.
这篇关于拦截器和过滤器之间的区别 - 这是对的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!