Springmvc filters and interceptors

1 What is a filter

Filter is to filter data, such as filtering vulgar text, modifying character encoding, etc.

2 What is an interceptor

3 How to use filters and interceptors

The first step is to define the filter/interceptor class

The second step is to register the filter/interceptor in web.xml, the purpose is to establish the corresponding relationship between them and the request.

4 When the filter is called

There are two places, the first is the frontmost position where the request comes, and the second is the last position where the request is returned to the user, that is, both ends of the pipeline.

5 When the interceptor is called

The three methods preHandle() are called before the request is processed, postHandle() is called after the request is processed and before the view is generated, and afterCompletion() is called after the entire request is completed.

6 The order in which filters and interceptors are called

Filters and interceptors are called in the order they are registered in web.xml.

7 Differences between filters and interceptors

Filters act like names, filtering characters in a request. Location decides.

For example, the interceptor can be redirected.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324889125&siteId=291194637