Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
* Mapping specification
* In the web application deployment descriptor, the following syntax is used to define the mapping:
* ■ A string starting with the '/' character and ending with the '/*' suffix is used for path matching.
* ■ The string starting with '*.' is used for extension mapping.
* ■ The empty string "" is a special URL pattern that maps exactly to the context root of the application, http://host:port/context-root/
* Request form. In this case, the path information is'/' and the servlet path and context path are empty strings (" ").
* ■ A string containing only the "/" character represents the applied "default" servlet. In this case, the servlet path is the request URL minus
* The following path and path information is null。
* ■ So other strings are used only for exact matches。
* Deployment will fail if a valid web.xml (after merging information from fragments and annotations) contains arbitrary url-patterns mapped to multiple servlets.
*
*
* Sample mapping set
* Look at the following set of mappings:
* Table 12-1 sample mapping set
* Path Pattern Servlet
*
* /foo/bar/* servlet1
* /baz/* servlet2
* /catalog servlet3
* *.bop servlet4
* Will produce the following behavior:
* Table 12-2. The incoming path is applied to the sample map
* Incoming Path Servlet Handling Request
*
* /foo/bar/index.html servlet1
* /foo/bar/index.bop servlet1
* /baz servlet2
* /baz/index.html servlet2
* /catalog servlet3
* /catalog/index.html “default” servlet
* /catalog/racecar.bop servlet4
* /index.bop servlet4
* Note that in the case of /catalog/index.html and /catalog/racecar.bop, the servlet mapped to "/catalog" is not used because it is not an exact match
*
* @author wangzihao
* Created on 2017-08-25 11:32.
*/
public class UrlMapper {
private final boolean singlePattern;
private final AntPathMatcher antPathMatcher = new AntPathMatcher();
private final Comparator super Element> addSortComparator = (o1, o2) -> o1.addSort < o2.addSort ? -1 : 1;
private int sort = 0;
private String rootPath;
private Collection> elementList = new TreeSet<>();
public UrlMapper(boolean singlePattern) {
this.singlePattern = singlePattern;
this.antPathMatcher.setCachePatterns(Boolean.TRUE);
}
public static String normPath(String path) {
if (path == null || path.isEmpty()) {
return path;
}
while (path.startsWith("//")) {
path = path.substring(1);
}
if (path.length() > 1) {
if (!path.startsWith("/")) {
path = "/" + path;
}
}
return path;
}
public static void main(String[] args) {
UrlMapper