Filter life cycle / execution flow :
1_ When the server starts , tomcat checks whether some filters <filter-class> have been configured in web.xml . If configured , call the internal path of <filter-class> , create a filter through reflection , and call the filter init method.init The method is executed only once .
2_When the client browser initiates a request to the server, it first arrives at tomcat, and Tomcat encapsulates the HTTP request part in the HttpServletRequest object , and creates the Htt pServletResponse object at the same time .
3_Tomcat looks at the resource to be accessed by this request , and sees whether the corresponding filter is triggered . If it is triggered , it will pass the created request and response to the filter method doFilter, and execute the code in doFilter
4_ If the release statement is executed in doFilter , then tomcat continues to execute the resource (servlet/jsp) to be accessed this time,
5_ After the accessed resource is executed , it goes through the filter again and responds to the client browser .
Performance improvement ? Good software ? Runs fast ( statement algorithm ), takes up less resources ( memory usage ).
Java servlet/jsp filter listener ServletConetxt
Destroy() does not destroy the filter object, he does some finishing work , such as closing the stream
What do filters do
Verify that the client is from a trusted network
Recode customer submitted data
Filter out some of the customer's words that should not appear
Verify that the user can log in
Verify that the client's browser supports the current application
record system log
Day41 Listener
Handling garbled characters
Get request adds URIEncodeing attribute=utf-8 in server.xml
New String()