1, filter is used to intercept user requests, before the server responds, you can modify the request and response after interception, so that many developers want to achieve the function.
2. Filter implementation
X write a class that inherits the filter interface
X describes this filter in the project's Web. xml file
<?xml version= "1.0" encoding= "UTF-8"?>
<web-app version= "2.5"
Xmlns= "Http://java.sun.com/xml/ns/javaee"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
Xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee
Http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd ">
<filter>
<filter-name>CharsetEcodingFilter2</filter-name>
<filter-class>cn.itcast.filter.CharsetEcodingFilter2</filter-class>
</filter>
<filter-mapping>
<filter-name>CharsetEcodingFilter2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
3. Common usage
x processing the whole station Chinese garbled problem
X for automatic Login
X filter Sensitive words
X Compress Web pages
X selectively allows the browser to cache
The same principle applies to the implementation of these features, which is to enhance the functionality of the request or Response object using wrapper mode or dynamic proxy.
"Filter" SPRINGMVC Web. xml