Difference between Interceptors and Filters - Is this right?

后端 未结 4 1430
长发绾君心
长发绾君心 2021-02-05 17:49

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 a

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-05 18:02

    Filters are from Servlet API and Interceptors are from Struts 2 , Difference comes when we talk about web applications and enterprise apps, filter is used only in web applications whereas interceptor can be used with web as well as enterprise applications. Life cycle methods of both, also differs.

    The interceptor stack fires on every request. filters only apply to the urls for which they are defined. you use one or the other depending on need. Lets say you need to verify a cookie is present for every request. Use an interceptor. Lets say that you need to pop up an external app on some requests (driven by a url), use a filter.

提交回复
热议问题