Home >Java >javaTutorial >What does java filter do?
The Java filter is a filter between the client and the server resource file. Before accessing the resource file, the request can be modified and judged through a series of filters, and the requests that do not comply with the rules can be modified. The request is intercepted or modified midway; the response can also be filtered, intercepted or modified.
Filters are also a commonly used part in Java and are used to restrict certain things. Let’s take a look at them below.
Filter is a filter between the client and the server resource file. Before accessing the resource file, the request is modified and judged through a series of filters. Requests that do not comply with the rules are intercepted or modified midway. Responses can also be filtered, intercepted or modified.
As shown in the figure, the request sent by the browser is first submitted to the first filter for filtering. If it meets the rules, it is released and submitted to the next filter in the filter chain for filtering. The order of filters in the chain is related to the order in which they are configured in web.xml. The one configured first is located at the front end of the chain. When the request passes all the filters in the chain, the resource file can be accessed. If it cannot pass, it may be processed in one of the intermediate filters.
In the doFilter() method, the code before chain.doFilter() is generally the filtering operation performed on the request, and the code after chain.doFilter is generally the operation performed on the response. The execution sequence of the filter chain code is as follows:
Filters are generally used for login permission verification, resource access permission control, sensitive word filtering, character encoding conversion and other operations to facilitate code Reuse, there is no need to perform corresponding operations in each servlet.
The above is the detailed content of What does java filter do?. For more information, please follow other related articles on the PHP Chinese website!