1, interceptors are based on the reflection mechanism of Java, and filter is based on function callback
2. The filter relies on the servlet container, and the interceptor does not depend on the servlet container
3.interceptors only work on action requests, while filters can work on almost all requests
4. Theinterceptor can access the action context, the object in the value stack, and the filter cannot
5, in the life cycle of the action , the interceptor can be called multiple times, and the filter can only be called once when the container is initialized
Interception Device : It is in the aspect programming that you call a method before your service or a method, or call a method after a method such as a dynamic proxy is a simple implementation of the Interceptor, before you call the method to print out the string (or do other business logic operations), You can also print out a string after you invoke the method, even if you do business logic when you throw an exception.
filter : Yes inJava Web, you pass in theRequest,responsefilter out some information in advance, or set some parameters in advance, and then pass inservletorStrutsof theActionconduct business logic, such as filtering out illegalURL(Notlogin.doaddress request, if the user does not log in are filtered out),or in the incomingservletorStrutsof theActionset the character set before, or remove some illegal characters.
using filters to filter the JSP pages in the/admin directory , first Filter configuration in Web. XML :
The difference between a filter and an interceptor