Class ServletUriComponentsBuilder
java.lang.Object
org.springframework.web.util.UriComponentsBuilder
org.springframework.web.servlet.support.ServletUriComponentsBuilder
- All Implemented Interfaces:
- Cloneable,- UriBuilder
UriComponentsBuilder with additional static factory methods to create links
 based on the current HttpServletRequest.
 
Note: As of 5.1, methods in this class do not extract
 "Forwarded" and "X-Forwarded-*" headers that specify the
 client-originated address. Please, use
 ForwardedHeaderFilter, or similar from the underlying server, to extract
 and use such headers, or to discard them.
- Since:
- 3.1
- Author:
- Rossen Stoyanchev
- 
Nested Class SummaryNested classes/interfaces inherited from class org.springframework.web.util.UriComponentsBuilderUriComponentsBuilder.ParserType
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedDefault constructor.protectedCreate a deep copy of the given ServletUriComponentsBuilder.
- 
Method SummaryModifier and TypeMethodDescriptionClone thisUriComponentsBuilder.static ServletUriComponentsBuilderfromContextPath(HttpServletRequest request) Prepare a builder from the host, port, scheme, and context path of the given HttpServletRequest.static ServletUriComponentsBuilderSame asfromContextPath(HttpServletRequest)except the request is obtained throughRequestContextHolder.static ServletUriComponentsBuilderSame asfromRequest(HttpServletRequest)except the request is obtained throughRequestContextHolder.static ServletUriComponentsBuilderSame asfromRequestUri(HttpServletRequest)except the request is obtained throughRequestContextHolder.static ServletUriComponentsBuilderSame asfromServletMapping(HttpServletRequest)except the request is obtained throughRequestContextHolder.static ServletUriComponentsBuilderfromRequest(HttpServletRequest request) Prepare a builder by copying the scheme, host, port, path, and query string of an HttpServletRequest.static ServletUriComponentsBuilderfromRequestUri(HttpServletRequest request) Prepare a builder from the host, port, scheme, and path (but not the query) of the HttpServletRequest.static ServletUriComponentsBuilderfromServletMapping(HttpServletRequest request) Prepare a builder from the host, port, scheme, context path, and servlet mapping of the given HttpServletRequest.protected static HttpServletRequestObtain current request throughRequestContextHolder.Remove any path extension from therequestURI.Methods inherited from class org.springframework.web.util.UriComponentsBuilderbuild, build, build, build, buildAndExpand, buildAndExpand, clone, encode, encode, fragment, fromHttpRequest, fromHttpUrl, fromOriginHeader, fromPath, fromUri, fromUriString, fromUriString, host, newInstance, path, pathSegment, port, port, query, queryParam, queryParam, queryParamIfPresent, queryParams, replacePath, replaceQuery, replaceQueryParam, replaceQueryParam, replaceQueryParams, scheme, schemeSpecificPart, toUriString, uri, uriComponents, uriVariables, userInfo
- 
Constructor Details- 
ServletUriComponentsBuilderprotected ServletUriComponentsBuilder()Default constructor. Protected to prevent direct instantiation.
- 
ServletUriComponentsBuilderCreate a deep copy of the given ServletUriComponentsBuilder.- Parameters:
- other- the other builder to copy from
 
 
- 
- 
Method Details- 
fromContextPathPrepare a builder from the host, port, scheme, and context path of the given HttpServletRequest.
- 
fromServletMappingPrepare a builder from the host, port, scheme, context path, and servlet mapping of the given HttpServletRequest.If the servlet is mapped by name, for example, "/main/*", the path will end with "/main". If the servlet is mapped otherwise, for example,"/"or"*.do", the result will be the same as if callingfromContextPath(HttpServletRequest).
- 
fromRequestUriPrepare a builder from the host, port, scheme, and path (but not the query) of the HttpServletRequest.
- 
fromRequestPrepare a builder by copying the scheme, host, port, path, and query string of an HttpServletRequest.
- 
fromCurrentContextPathSame asfromContextPath(HttpServletRequest)except the request is obtained throughRequestContextHolder.
- 
fromCurrentServletMappingSame asfromServletMapping(HttpServletRequest)except the request is obtained throughRequestContextHolder.
- 
fromCurrentRequestUriSame asfromRequestUri(HttpServletRequest)except the request is obtained throughRequestContextHolder.
- 
fromCurrentRequestSame asfromRequest(HttpServletRequest)except the request is obtained throughRequestContextHolder.
- 
getCurrentRequestObtain current request throughRequestContextHolder.
- 
removePathExtensionRemove any path extension from therequestURI. This method must be invoked before any calls toUriComponentsBuilder.path(String)orUriComponentsBuilder.pathSegment(String...).GET http://www.foo.example/rest/books/6.json ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromRequestUri(this.request); String ext = builder.removePathExtension(); String uri = builder.path("/pages/1.{ext}").buildAndExpand(ext).toUriString(); assertEquals("http://www.foo.example/rest/books/6/pages/1.json", result);- Returns:
- the removed path extension for possible re-use, or null
- Since:
- 4.0
 
- 
cloneBuilderDescription copied from class:UriComponentsBuilderClone thisUriComponentsBuilder.- Overrides:
- cloneBuilderin class- UriComponentsBuilder
- Returns:
- the cloned UriComponentsBuilderobject
 
 
-