Servlet Filter and the implementation of the principle of

A, Servlet two Map

  When the request arrives, web Servlet container is how to find it? What is the implementation process?

  I, like many people might only know to configure blocking rules in the web, xml, and then reflected + maps to get away?

  When the Servlet solid column is created, the Servlet can reference stored into a solid column of the Map, the Map of K is url, V is a real reference column Servlet +

  即Map<String,Servlet>

  When the vessel was isolated URI Web request from a user, whether this will first and Map to find the corresponding Value, i.e., reference Servlet

  If present, will call the service method using the same, if not, you need to create the actual column Servlet

  If the requested real Servlet column does not exist, this wave will have the following operations

  Memory web container, it is also saved in a Map Map K is the set of URI, V is the fully qualified name of the corresponding Servlet arranged in web.xml

  即Map<String,String>

  When the Web container separated from the user in the request URI, the first corresponding to a Map and no reference to find Servlet,

  So he ran second in the Map to find, to find its corresponding class name, then the reflection mechanism to create the Servlet real column,

  And finally had to put the real column reference into the first Map, predecessors trees descendants cool.

Second, a Map of an array Filter

  Map Servlet like two store information, like the presence of the same Map Filter used to store information in the server

  But only a Map, because creating opportunity Filter is different from the Servlet, which is created automatically by the Web container when the server starts

  The Filter is a K-Map <URL-pattern /> ,

  Of course, if no Filter Set <url-pattern>, but the use of <servlet-name />

  It will be developed by the Servlet <url-pattern> K as a value into the Map

  Map of V Filter references for

  When the application is started, the server will automatically create all of the real Filter column, and them one by one into Map

  In the server, each request for an array there is, for all resource Filter and ultimate goal of satisfying the current request

  When the request reaches the server, the server parses the URI, first query the Map matching the request Filter

  Each found to meet the requirements of a Filter, which will be put into the array, until all of the Filter After filtration

  The array is stored in the request matches the Filter can be seen as a "chain", the server will process the request in order sequentially filtered

Third, pay attention

  For Map Filter is concerned, the query will filter all the Key, will comply with all matches are loaded into an array

  The query process Map of Servlet is, just find a matching Key, looking back will not go down

 

Guess you like

Origin www.cnblogs.com/msi-chen/p/10974893.html