Home > Java > Javagetting Started > body text

What is the difference between filter and interceptor

王林
Release: 2020-11-17 17:00:16
Original
15249 people have browsed it

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.

What is the difference between filter and interceptor

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!