Servlet url-patten, Servleturl-patten
By default, the container client requests a Servlet, so it does not directly search for files from the server based on the path. When a request is sent to the servlet container, the container first uses the requested url minus the current application context path as the servlet Path. Search for the corresponding Servlet File Based on <url-pattern> in web. xml. After the matching is successful, the matching will stop. If the matching fails, the matching will be found from the folder. If none of them are found, 404 is returned.
Url-patternMatching rulesOnly (* As a wildcard):
■ A string starting with "/" and ending with "/*" is used for path ing.
<Url-pattern>/user/* </url-pattern>
Http: // localhost: 5555/myapp/user (it can also be matched, * the wildcard is equivalent to null)
Http: /localhost: 5555/myapp/user/addUser. action
Http: /localhost: 5555/myapp/user/updateUser. action
■ Strings starting with "*." are used for extension ing.
<Url-pattern> *. do </url-pattern>
Http: // localhost: 5555/myapp/item/order. do
Http: /localhost: 5555/myapp/user/test. do
■ An empty string ("") is used to specify the URL mode for precisely ing the application context root, for example, requests from http: // host: port/<contextroot>. In this case, the path information is "/", and the servlet Path and context path are an empty string ("").
■ If the string contains only the "/" character, it indicates the application's "default" servlet. In this case, the servlet Path is requested to remove the context path from the URI and the path information is null.
'/' Matches all requests with the lowest priority. It is used to process access requests (including access to static resources) that are not processed by other servlets ). If the corresponding. jsp file exists, the file will be sent instead of being transferred to the default servlet for processing. Because tomcat not only configures the default serlvlet, but also has the built-in url-pattern of *. jspx and *. jsp.
<Servlet-mapping>
<Servlet-name> default </servlet-name>
<Url-pattern>/</url-pattern>
</Servlet-mapping>
■Other types of strings belong to exact match.
The servlet Path must exactly match the configuration in <url-pattern>.
Matching order:
Exact match> path match (long path> short path)> extension match> default match
Tomcat matches the servlet Path with the url-pattern in web. xml in sequence.
Note:
The matching rules cannot be used in combination. Both Path Matching and extension matching are invalid at the same time:
<Url-pattern>/kata/*. jsp </url-pattern>
<Url-pattern>/*. jsp </url-pattern>
<Url-pattern> he *. jsp </url-pattern>
<Url-pattern>/user/*. action </url-pattern>
"/*" Path Matching, The priority is higher than the extension matching, so it usually causes 404 errors. All requests (including static resource requests) can be matched ). If the corresponding. jsp/. html file exists, the request will still be sent to the corresponding servlet for processing.This url-pattern is generally used only for filter.