How does a servlets filter identify next destination is another filter or a servlet/jsp?

前端 未结 1 507
Happy的楠姐
Happy的楠姐 2020-12-07 04:59

We usually end up with writing /* in web.xml for any Filter in servlets.


    

        
1条回答
  •  执笔经年
    2020-12-07 05:42

    Servlet Matching Procedure

    A request may match more than one servlet-mapping in a given context. The servlet container uses a straightforward matching procedure to determine the best match.

    The matching procedure has four simple rules.

    • First, the container prefers an exact path match over a wildcard path match.

    • Second, the container prefers to match the longest pattern.

    • Third, the container prefers path matches over filetype matches.

    • Finally, the pattern / always matches any request that no other pattern matches.


    For example, a context web.xml file can map the home page for an online catalog to one pattern and the search page for the catalog to a different pattern, as shown below:

    
      catalogBrowse
      /Catalog/*
    
    
    
      catalogSearch
      /Catalog/search/*
    
    

    Below figure illustrates the matching process for a context. Since the container prefers to match the longest pattern, a URL that includes /Catalog/search/ always matches the mapping for catalogSearch rather than the mapping for catalogBrowse.

    URL pattern matching

    enter image description here


    It is copied form the below link if your are not interested to go to the link.

    Please have a look at URL Patterns where it is described in detail with examples.

    0 讨论(0)
提交回复
热议问题