public class UrlMapper<T> extends Object
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
| 限定符和类型 | 类和说明 |
|---|---|
static class |
UrlMapper.Element<T> |
| 构造器和说明 |
|---|
UrlMapper(boolean singlePattern) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
addMapping(String urlPattern,
T object,
String objectName)
Add mapping
|
void |
addMappingObjectsByUri(String absoluteUri,
List<UrlMapper.Element<T>> list)
Add multiple mapping objects
|
void |
clear() |
UrlMapper.Element<T> |
getMappingObjectByUri(String absoluteUri)
Gets a mapping object
|
String |
getServletPath(String absoluteUri)
Gets a servlet path
|
static void |
main(String[] args) |
static String |
normPath(String path) |
void |
removeMapping(String objectName)
Delete the mapping
|
void |
setRootPath(String rootPath) |
public static void main(String[] args)
public void clear()
public void setRootPath(String rootPath)
public void addMapping(String urlPattern, T object, String objectName) throws IllegalArgumentException
urlPattern - urlPatternobject - objectobjectName - objectNameIllegalArgumentException - IllegalArgumentExceptionpublic void removeMapping(String objectName)
objectName - objectNamepublic String getServletPath(String absoluteUri)
absoluteUri - An absolute pathpublic UrlMapper.Element<T> getMappingObjectByUri(String absoluteUri)
absoluteUri - An absolute pathpublic void addMappingObjectsByUri(String absoluteUri, List<UrlMapper.Element<T>> list)
list - add in listabsoluteUri - An absolute pathCopyright © 2023. All rights reserved.