"Oracle Java EE Programming Guide" 12-02: Filter related API

Filter related API

Servlet API, the API associated with the filter has three interfaces, namely,

  • Filter
  • FilterChain
  • FilterConfig
    this section only to understand the fundamental role of the API, the next section will use the example of learning to use

Filter interface

Filter interface is a filter class must implement the interface, which has three methods.

init (FilterConfig filterConfig): This method is a method to filter object initialized called only once after the end of the container to initialize filter object. FilterConfig parameters can be obtained in the initialization parameter filter (initialization parameters see the following section).
doFilter (ServletRequest request, ServletResponse response, FilterChain chain): This method is a method for filtering a filter, is the most important method. Filter implementation class must implement the method. Method body may be pretreated request and response. Which may be treated FilterChain request and response objects passed to the next filter in the chain of resources
destroy (): This method is called before the destruction of the object in the filter vessel.

FilterChain Interface

This interface type is used as the parameter Filter doFilter interface method. FilterChain interface has a method
doFilter (ServletRequest request, ServletResponse response) , which may be in response to the current request and passed to the next filter in the chain of resources, may be the next filter, it may be the target resource.

FilterConfig Interface

This interface type as a parameter init Filter interface method used, FilterConfig interface has a common method
getInitParameter (String name), which is used to initialize the parameters of the filter obtained. In web.xml initialization parameters need to configure for each filter, similar to the Servlet. Filter initialization parameters can be obtained by the method FilterConfig in getInitParameter.

Guess you like

Origin blog.csdn.net/goldentec/article/details/105337360