Use of url-pattern in JavaWeb Servlet, javaweburl-pattern
Use of url-pattern in Java Web Servlet
1. Description of Sevlet and Filter url-pattern
A page request matches only one best Servlet according to url-pattern, and generates a FilterChain based on one or more filters that meet the requirements according to the filter-mapping tag sequence of web. xml.
2. url-pattern Configuration
Configure the web. xml file to define the meaning of the ing:
(1). "/" --> path ing
(2). "*. do" prefix --> extended ing
(3). "/" --> default servlet ing.
(4). Detailed Definition
<Url-pattern>/*. do </url-pattern> Invalid <url-pattern>/*. do in servlet mapping Error
Because "/" matches the path ing and the extended ing, the container cannot judge.
3. url-pattern matching rules
(1). Exact Path Matching
Where the exact matching requirements are met, precision is the main factor;
(2). Longest Path Matching
For example, the url-pattern of servletA is/test /*,
The url-pattern of servletB is/test//*,
Http: // localhost/test/a --> servletB
(3). Extended matching
The container selects the appropriate servlet Based on the extension.
If you have any questions, please leave a message or go to the community on this site for discussion. Thank you for reading this article. Thank you for your support!