类 UrlPathHelper
RequestDispatcher includes and support for consistent URL decoding.- 从以下版本开始:
- 4.0 2022/4/7 21:34
- 作者:
- Juergen Hoeller, Rob Harrop, Rossen Stoyanchev, Harry Yang
- 另请参阅:
-
字段概要
字段修饰符和类型字段说明private booleanprivate Stringstatic final UrlPathHelperShared, read-only instance with defaults.private static final cn.taketoday.logging.Loggerstatic final StringName of Servlet request attribute that holds aresolvedlookupPath.static final UrlPathHelperShared, read-only instance for the full, encoded path.private booleanprivate booleanprivate booleanprivate static final StringSpecial WebSphere request attribute, indicating the original request URI.(专用程序包) static Boolean -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明private voidprivate StringdecodeAndCleanUriString(HttpServletRequest request, String uri) Decode the supplied URI string and strips any extraneous portion after a ';'.private StringdecodeInternal(HttpServletRequest request, String source) decodeMatrixVariables(HttpServletRequest request, cn.taketoday.util.MultiValueMap<String, String> vars) Decode the given matrix variables viadecodeRequestString(jakarta.servlet.http.HttpServletRequest, java.lang.String)unlesssetUrlDecode(boolean)is set totruein which case it is assumed the URL path from which the variables were extracted is already decoded through a call togetLookupPathForRequest(HttpServletRequest).decodePathVariables(HttpServletRequest request, Map<String, String> vars) Decode the given URI path variables viadecodeRequestString(jakarta.servlet.http.HttpServletRequest, java.lang.String)unlesssetUrlDecode(boolean)is set totruein which case it is assumed the URL path from which the variables were extracted is already decoded through a call togetLookupPathForRequest(HttpServletRequest).decodeRequestString(HttpServletRequest request, String source) Decode the given source string with a URLDecoder.protected StringdetermineEncoding(HttpServletRequest request) Determine the encoding for the given request.getContextPath(HttpServletRequest request) Return the context path for the given request, detecting an include request URL if called within a RequestDispatcher include.protected StringReturn the default character encoding to use for URL decoding.Return the mapping lookup path for the given request, within the current servlet mapping if applicable, else within the web application.getLookupPathForRequest(HttpServletRequest request, String name) 已过时。Return the context path for the given request, detecting an include request URL if called within a RequestDispatcher include.Return the query string part of the given request's URL.Return the request URI for the given request.Return the servlet path for the given request, detecting an include request URL if called within a RequestDispatcher include.Return the path within the web application for the given request.Return the path within the servlet mapping for the given request, i.e. the part of the request's URL beyond the part that called the servlet, or "" if the whole URL has been used to identify the servlet.protected StringgetPathWithinServletMapping(HttpServletRequest request, String pathWithinApp) Return the path within the servlet mapping for the given request, i.e. the part of the request's URL beyond the part that called the servlet, or "" if the whole URL has been used to identify the servlet.private StringgetRemainingPath(String requestUri, String mapping, boolean ignoreCase) Match the given "mapping" to the start of the "requestUri" and if there is a match return the extra part.getRequestUri(HttpServletRequest request) Return the request URI for the given request, detecting an include request URL if called within a RequestDispatcher include.static StringgetResolvedLookupPath(ServletRequest request) Return a previouslyresolvedlookupPath.private static StringgetSanitizedPath(String path) Sanitize the given path.getServletPath(HttpServletRequest request) Return the servlet path for the given request, regarding an include request URL if called within a RequestDispatcher include.booleanWhether to decode the request URI when determining the lookup path.private StringremoveJsessionid(String requestUri) removeSemicolonContent(String requestUri) Remove ";" (semicolon) content from the given request URI if the removeSemicolonContent property is set to "true".private static StringremoveSemicolonContentInternal(String requestUri) Resolvethe lookupPath and cache it in a request attribute with the keyPATH_ATTRIBUTEfor subsequent access viagetResolvedLookupPath(ServletRequest).voidsetAlwaysUseFullPath(boolean alwaysUseFullPath) Whether URL lookups should always use the full path within the current web application context, i.e. withinServletContext.getContextPath().voidsetDefaultEncoding(String defaultEncoding) Set the default character encoding to use for URL decoding.private voidSwitch to read-only mode where further configuration changes are not allowed.voidsetRemoveSemicolonContent(boolean removeSemicolonContent) Set if ";" (semicolon) content should be stripped from the request URI.voidsetUrlDecode(boolean urlDecode) Whether the context path and request URI should be decoded -- both of which are returned undecoded by the Servlet API, in contrast to the servlet path.booleanWhether configured to remove ";" (semicolon) content from the request URI.private booleanprivate booleanCheck whether servlet path determination can be skipped for the given request.
-
字段详细资料
-
PATH_ATTRIBUTE
Name of Servlet request attribute that holds aresolvedlookupPath. -
WEBSPHERE_URI_ATTRIBUTE
Special WebSphere request attribute, indicating the original request URI. Preferable over the standard Servlet 2.4 forward attribute on WebSphere, simply because we need the very first URI in the request forwarding chain.- 另请参阅:
-
log
private static final cn.taketoday.logging.Logger log -
websphereComplianceFlag
-
alwaysUseFullPath
private boolean alwaysUseFullPath -
urlDecode
private boolean urlDecode -
removeSemicolonContent
private boolean removeSemicolonContent -
defaultEncoding
-
readOnly
private boolean readOnly -
defaultInstance
Shared, read-only instance with defaults. The following apply:alwaysUseFullPath=falseurlDecode=trueremoveSemicolon=truedefaultEncoding=Constant.DEFAULT_ENCODING
-
rawPathInstance
Shared, read-only instance for the full, encoded path. The following apply:alwaysUseFullPath=trueurlDecode=falseremoveSemicolon=falsedefaultEncoding=Constant.DEFAULT_ENCODING
-
-
构造器详细资料
-
UrlPathHelper
public UrlPathHelper()
-
-
方法详细资料
-
setAlwaysUseFullPath
public void setAlwaysUseFullPath(boolean alwaysUseFullPath) Whether URL lookups should always use the full path within the current web application context, i.e. withinServletContext.getContextPath().If set to false the path within the current servlet mapping is used instead if applicable (i.e. in the case of a prefix based Servlet mapping such as "/myServlet/*").
By default this is set to "false".
-
setUrlDecode
public void setUrlDecode(boolean urlDecode) Whether the context path and request URI should be decoded -- both of which are returned undecoded by the Servlet API, in contrast to the servlet path.Either the request encoding or the default Servlet spec encoding (ISO-8859-1) is used when set to "true".
By default this is set to true.
Note: Be aware the servlet path will not match when compared to encoded paths. Therefore use of
urlDecode=falseis not compatible with a prefix-based Servlet mapping and likewise implies also settingalwaysUseFullPath=true. -
isUrlDecode
public boolean isUrlDecode()Whether to decode the request URI when determining the lookup path. -
setRemoveSemicolonContent
public void setRemoveSemicolonContent(boolean removeSemicolonContent) Set if ";" (semicolon) content should be stripped from the request URI.Default is "true".
-
shouldRemoveSemicolonContent
public boolean shouldRemoveSemicolonContent()Whether configured to remove ";" (semicolon) content from the request URI. -
setDefaultEncoding
Set the default character encoding to use for URL decoding. Default is ISO-8859-1, according to the Servlet spec.If the request specifies a character encoding itself, the request encoding will override this setting. This also allows for generically overriding the character encoding in a filter that invokes the
ServletRequest.setCharacterEncodingmethod.- 参数:
defaultEncoding- the character encoding to use- 另请参阅:
-
getDefaultEncoding
Return the default character encoding to use for URL decoding. -
setReadOnly
private void setReadOnly()Switch to read-only mode where further configuration changes are not allowed. -
checkReadOnly
private void checkReadOnly() -
resolveAndCacheLookupPath
Resolvethe lookupPath and cache it in a request attribute with the keyPATH_ATTRIBUTEfor subsequent access viagetResolvedLookupPath(ServletRequest).- 参数:
request- the current request- 返回:
- the resolved path
-
getResolvedLookupPath
Return a previouslyresolvedlookupPath.- 参数:
request- the current request- 返回:
- the previously resolved lookupPath
- 抛出:
IllegalArgumentException- if the not found
-
getLookupPathForRequest
@Deprecated public String getLookupPathForRequest(HttpServletRequest request, @Nullable String name) 已过时。in favor of usingresolveAndCacheLookupPath(HttpServletRequest)andgetResolvedLookupPath(ServletRequest).Variant ofgetLookupPathForRequest(HttpServletRequest)that automates checking for a previously computed lookupPath saved as a request attribute. The attribute is only used for lookup purposes.- 参数:
request- current HTTP requestname- the request attribute that holds the lookupPath- 返回:
- the lookup path
-
getLookupPathForRequest
Return the mapping lookup path for the given request, within the current servlet mapping if applicable, else within the web application.Detects include request URL if called within a RequestDispatcher include.
- 参数:
request- current HTTP request- 返回:
- the lookup path
- 另请参阅:
-
skipServletPathDetermination
Check whether servlet path determination can be skipped for the given request.- 参数:
request- current HTTP request- 返回:
trueif the request mapping has not been achieved using a path or if the servlet has been mapped to root;falseotherwise
-
getPathWithinServletMapping
Return the path within the servlet mapping for the given request, i.e. the part of the request's URL beyond the part that called the servlet, or "" if the whole URL has been used to identify the servlet.- 参数:
request- current HTTP request- 返回:
- the path within the servlet mapping, or ""
- 另请参阅:
-
getPathWithinServletMapping
Return the path within the servlet mapping for the given request, i.e. the part of the request's URL beyond the part that called the servlet, or "" if the whole URL has been used to identify the servlet.Detects include request URL if called within a RequestDispatcher include.
E.g.: servlet mapping = "/*"; request URI = "/test/a" → "/test/a".
E.g.: servlet mapping = "/"; request URI = "/test/a" → "/test/a".
E.g.: servlet mapping = "/test/*"; request URI = "/test/a" → "/a".
E.g.: servlet mapping = "/test"; request URI = "/test" → "".
E.g.: servlet mapping = "/*.test"; request URI = "/a.test" → "".
- 参数:
request- current HTTP requestpathWithinApp- a precomputed path within the application- 返回:
- the path within the servlet mapping, or ""
- 另请参阅:
-
getPathWithinApplication
Return the path within the web application for the given request.Detects include request URL if called within a RequestDispatcher include.
- 参数:
request- current HTTP request- 返回:
- the path within the web application
- 另请参阅:
-
getRemainingPath
Match the given "mapping" to the start of the "requestUri" and if there is a match return the extra part. This method is needed because the context path and the servlet path returned by the HttpServletRequest are stripped of semicolon content unlike the requestUri. -
getSanitizedPath
Sanitize the given path. Uses the following rules:- replace all "//" by "/"
-
getRequestUri
Return the request URI for the given request, detecting an include request URL if called within a RequestDispatcher include.As the value returned by
request.getRequestURI()is not decoded by the servlet container, this method will decode it.The URI that the web container resolves should be correct, but some containers like JBoss/Jetty incorrectly include ";" strings like ";jsessionid" in the URI. This method cuts off such incorrect appendices.
- 参数:
request- current HTTP request- 返回:
- the request URI
-
getContextPath
Return the context path for the given request, detecting an include request URL if called within a RequestDispatcher include.As the value returned by
request.getContextPath()is not decoded by the servlet container, this method will decode it.- 参数:
request- current HTTP request- 返回:
- the context path
-
getServletPath
Return the servlet path for the given request, regarding an include request URL if called within a RequestDispatcher include.As the value returned by
request.getServletPath()is already decoded by the servlet container, this method will not attempt to decode it.- 参数:
request- current HTTP request- 返回:
- the servlet path
-
getOriginatingRequestUri
Return the request URI for the given request. If this is a forwarded request, correctly resolves to the request URI of the original request. -
getOriginatingContextPath
Return the context path for the given request, detecting an include request URL if called within a RequestDispatcher include.As the value returned by
request.getContextPath()is not decoded by the servlet container, this method will decode it.- 参数:
request- current HTTP request- 返回:
- the context path
-
getOriginatingServletPath
Return the servlet path for the given request, detecting an include request URL if called within a RequestDispatcher include.- 参数:
request- current HTTP request- 返回:
- the servlet path
-
getOriginatingQueryString
Return the query string part of the given request's URL. If this is a forwarded request, correctly resolves to the query string of the original request.- 参数:
request- current HTTP request- 返回:
- the query string
-
decodeAndCleanUriString
Decode the supplied URI string and strips any extraneous portion after a ';'. -
decodeRequestString
Decode the given source string with a URLDecoder. The encoding will be taken from the request, falling back to the default "ISO-8859-1".The default implementation uses
URLDecoder.decode(input, enc).- 参数:
request- current HTTP requestsource- the String to decode- 返回:
- the decoded String
- 另请参阅:
-
Constant.DEFAULT_ENCODINGServletRequest.getCharacterEncoding()URLDecoder.decode(String, String)URLDecoder.decode(String)
-
decodeInternal
-
determineEncoding
Determine the encoding for the given request. Can be overridden in subclasses.The default implementation checks the request encoding, falling back to the default encoding specified for this resolver.
- 参数:
request- current HTTP request- 返回:
- the encoding for the request (never
null) - 另请参阅:
-
removeSemicolonContent
Remove ";" (semicolon) content from the given request URI if the removeSemicolonContent property is set to "true". Note that "jsessionid" is always removed.- 参数:
requestUri- the request URI string to remove ";" content from- 返回:
- the updated URI string
-
removeSemicolonContentInternal
-
removeJsessionid
-
decodePathVariables
Decode the given URI path variables viadecodeRequestString(jakarta.servlet.http.HttpServletRequest, java.lang.String)unlesssetUrlDecode(boolean)is set totruein which case it is assumed the URL path from which the variables were extracted is already decoded through a call togetLookupPathForRequest(HttpServletRequest).- 参数:
request- current HTTP requestvars- the URI variables extracted from the URL path- 返回:
- the same Map or a new Map instance
-
decodeMatrixVariables
public cn.taketoday.util.MultiValueMap<String,String> decodeMatrixVariables(HttpServletRequest request, cn.taketoday.util.MultiValueMap<String, String> vars) Decode the given matrix variables viadecodeRequestString(jakarta.servlet.http.HttpServletRequest, java.lang.String)unlesssetUrlDecode(boolean)is set totruein which case it is assumed the URL path from which the variables were extracted is already decoded through a call togetLookupPathForRequest(HttpServletRequest).- 参数:
request- current HTTP requestvars- the URI variables extracted from the URL path- 返回:
- the same Map or a new Map instance
-
shouldRemoveTrailingServletPathSlash
-
resolveAndCacheLookupPath(HttpServletRequest)andgetResolvedLookupPath(ServletRequest).