File filters, overview.

1 concept:

    * Filter life: water purifier. Air purifier, bandit.

    * Web the filter: when access to server resources, the filter may be intercepted request, perform specific functions.

    * Filter effects:

      The general use for completing the operation. Such as: login authentication, unified coding process, sensitive string filtering. . .

    Getting Started:  

      Step 1:

        1 define a class that implements the interface Filter

        2 replication method

        3 interceptor configuration path

          1web.xml

          2 NOTE Using @WebFilter ( "/ interception Path")

     2. Filters execution process

        1 performs filter

        2 execution resources after release

        3 final performance filters release code.

    Method 3 filter lifecycle

      1init: After the server is started, it will create a Filter object, and then call the init method, is performed only once. For loading resources

      2doFilter: every resource request is intercepted, it will execute, execute multiple times

      3destory: After the server is shut down, Filter object is destroyed. If the server is shut down properly, it will perform destory method for releasing resources.

    Detailed filter configuration 4

      1 specific resource path: /index.jsp only access index.jsp resources, the filter will be executed

      2 interceptions directory: / user / * to access / all of the resources of the user, the filter will be executed

      3 interceptor extension: * .jsp suffix is ​​access filter will be executed when the resource jsp

      4 interceptions all resources / * access any resources will be blocked

 

    Interception way configurations: the way resources are accessed

      Notes Configuration

      Set dispatcherTypes property    

        1REQUEST: default. Direct browser requests a resource

        2FORWARD: Forwarding access to resources  

        3INCLUDE: includes access to resources

        3Error: Error Jump Resources

      web.xml Configuration

        * Set <dispatcherTypes> </ dispatcherTypes> tag.

 

  Filter chain (a plurality of filter)

      Execution order

        Filter 1 1

        2 Filter 2

        3 execution resources

        4 filter 2

        Filter 1 5

    The execution order of the filter has    

      1 comment Configuration: To compare string comparison rules in accordance with the class name, the small value of the first implementation  

        As Afileter and Bfilter it will first perform Afilter

      2web.xml Configuration

        Arranged in the order, the configuration of the foregoing first implementation ye

 

General use httpServletRequest

  And httpServletRequest can get url or uri

        

Guess you like

Origin www.cnblogs.com/qmk-716/p/12154454.html