The difference between filters and interceptors is: 1. The interceptor is based on the java reflection mechanism, and the filter is based on function callbacks; 2. The interceptor does not depend on the servlet container, and the filter depends on the servlet container; 3. Interception The filter only works on action requests, and the filter can work on almost all requests.
The difference between filters and interceptors is as follows:
(Learning video sharing: java video tutorial)
1. The interceptor is based on java's reflection mechanism, while the filter is based on function callbacks.
2. The interceptor does not depend on the servlet container, but the filter depends on the servlet container.
3. Interceptors can only work on action requests, while filters can work on almost all requests.
4. Interceptors can access objects in the action context and value stack, but filters cannot.
5. In the life cycle of the action, the interceptor can be called multiple times, but the filter can only be called once when the container is initialized.
6. The interceptor can obtain each bean in the IOC container, but the filter cannot. This is very important. Injecting a service into the interceptor can call business logic.
Related recommended tutorials: Getting started with java
The above is the detailed content of What is the difference between filter and interceptor. For more information, please follow other related articles on the PHP Chinese website!