Class ServletRequestPathUtils
RequestPath
representation of the path when use of
parsed patterns
is enabled or a String path for use with a
PathMatcher otherwise.- Since:
- 5.3
- Author:
- Rossen Stoyanchev, Stephane Nicoll
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringName of Servlet request attribute that holds the parsedRequestPath.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic voidclearParsedRequestPath(jakarta.servlet.ServletRequest request) static ObjectgetCachedPath(jakarta.servlet.ServletRequest request) static StringgetCachedPathValue(jakarta.servlet.ServletRequest request) Variant ofgetCachedPath(ServletRequest)that returns the path for request mapping as a String.static RequestPathgetParsedRequestPath(jakarta.servlet.ServletRequest request) Return apreviouslyparsed and cachedRequestPath.getServletPathPrefix(jakarta.servlet.http.HttpServletRequest request) Check if the Servlet is mapped by a path prefix, and if so return that path prefix.static booleanhasCachedPath(jakarta.servlet.ServletRequest request) static booleanhasParsedRequestPath(jakarta.servlet.ServletRequest request) Check for apreviouslyparsed and cachedRequestPath.static RequestPathparse(jakarta.servlet.http.HttpServletRequest request) Parse therequestURIto aRequestPath.static RequestPathparseAndCache(jakarta.servlet.http.HttpServletRequest request) Variant ofparse(HttpServletRequest)that also saves the parsed path in the request attributePATH_ATTRIBUTE.static voidsetParsedRequestPath(@Nullable RequestPath requestPath, jakarta.servlet.ServletRequest request) Set the cached, parsedRequestPathto the given value.
- 
Field Details- 
PATH_ATTRIBUTEName of Servlet request attribute that holds the parsedRequestPath.
 
- 
- 
Constructor Details- 
ServletRequestPathUtilspublic ServletRequestPathUtils()
 
- 
- 
Method Details- 
parseParse therequestURIto aRequestPath.The returned RequestPathwill have both the contextPath and any servletPath prefix omitted from thepathWithinApplicationit exposes.- Since:
- 6.2.12
 
- 
parseAndCacheVariant ofparse(HttpServletRequest)that also saves the parsed path in the request attributePATH_ATTRIBUTE.
- 
getParsedRequestPathReturn apreviouslyparsed and cachedRequestPath.- Throws:
- IllegalArgumentException- if not found
 
- 
setParsedRequestPathpublic static void setParsedRequestPath(@Nullable RequestPath requestPath, jakarta.servlet.ServletRequest request) Set the cached, parsedRequestPathto the given value.- Parameters:
- requestPath- the value to set to, or if- nullthe cache value is cleared.
- request- the current request
- Since:
- 5.3.3
 
- 
hasParsedRequestPathpublic static boolean hasParsedRequestPath(jakarta.servlet.ServletRequest request) Check for apreviouslyparsed and cachedRequestPath.
- 
clearParsedRequestPathpublic static void clearParsedRequestPath(jakarta.servlet.ServletRequest request) 
- 
getCachedPathReturn either apre-resolvedString lookupPath or apre-parsedRequestPath.In Spring MVC, when at least one HandlerMappinghas parsedPathPatternsenabled, theDispatcherServletparses and caches theRequestPathwhich can be also done even earlier withServletRequestPathFilter. In other cases whereHandlerMappings use String pattern matching withPathMatcher, the String lookupPath is resolved separately in eachHandlerMapping.- Parameters:
- request- the current request
- Returns:
- a String lookupPath or a RequestPath
- Throws:
- IllegalArgumentException- if neither is available
 
- 
getCachedPathValueVariant ofgetCachedPath(ServletRequest)that returns the path for request mapping as a String.If the cached path is a pre-parsedRequestPaththen the returned String path value is encoded and with path parameters removed.If the cached path is a pre-resolvedString lookupPath, then the returned String path value depends on howUrlPathHelperthat resolved is configured.- Parameters:
- request- the current request
- Returns:
- the full request mapping path as a String
 
- 
hasCachedPath
- 
getServletPathPrefixpublic static @Nullable String getServletPathPrefix(jakarta.servlet.http.HttpServletRequest request) Check if the Servlet is mapped by a path prefix, and if so return that path prefix.- Parameters:
- request- the current request
- Returns:
- the prefix, or nullif the Servlet is not mapped by prefix
- Since:
- 6.2.3
 
 
-