org.springframework.web.servlet.support
Class ServletUriComponentsBuilder

java.lang.Object
  extended by org.springframework.web.util.UriComponentsBuilder
      extended by org.springframework.web.servlet.support.ServletUriComponentsBuilder

public class ServletUriComponentsBuilder
extends UriComponentsBuilder

A builder for UriComponents that offers static factory methods to extract information from an HttpServletRequest.

Since:
3.1
Author:
Rossen Stoyanchev

Constructor Summary
protected ServletUriComponentsBuilder()
          Default constructor.
 
Method Summary
static ServletUriComponentsBuilder fromContextPath(HttpServletRequest request)
          Return a builder initialized with the host, port, scheme, and the context path of the given request.
static ServletUriComponentsBuilder fromCurrentContextPath()
          Equivalent to fromContextPath(HttpServletRequest) except the request is obtained via RequestContextHolder.
static ServletUriComponentsBuilder fromCurrentRequest()
          Equivalent to fromRequest(HttpServletRequest) except the request is obtained via RequestContextHolder.
static ServletUriComponentsBuilder fromCurrentServletMapping()
          Equivalent to fromServletMapping(HttpServletRequest) except the request is obtained via RequestContextHolder.
static ServletUriComponentsBuilder fromRequest(HttpServletRequest request)
          Return a builder initialized with all available information in the given request including scheme, host, port, path, and query string.
static ServletUriComponentsBuilder fromServletMapping(HttpServletRequest request)
          Return a builder initialized with the host, port, scheme, context path, and the servlet mapping of the given request.
 
Methods inherited from class org.springframework.web.util.UriComponentsBuilder
build, build, buildAndExpand, buildAndExpand, fragment, fromHttpUrl, fromPath, fromUri, fromUriString, host, newInstance, path, pathSegment, port, query, queryParam, replacePath, replaceQuery, replaceQueryParam, scheme, uri, userInfo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServletUriComponentsBuilder

protected ServletUriComponentsBuilder()
Default constructor. Protected to prevent direct instantiation.

See Also:
fromContextPath(HttpServletRequest), fromServletMapping(HttpServletRequest), fromRequest(HttpServletRequest), fromCurrentContextPath(), fromCurrentServletMapping(), fromCurrentRequest()
Method Detail

fromContextPath

public static ServletUriComponentsBuilder fromContextPath(HttpServletRequest request)
Return a builder initialized with the host, port, scheme, and the context path of the given request.


fromServletMapping

public static ServletUriComponentsBuilder fromServletMapping(HttpServletRequest request)
Return a builder initialized with the host, port, scheme, context path, and the servlet mapping of the given request.

For example if the servlet is mapped by name, i.e. "/main/*", then the resulting path will be /appContext/main. If the servlet path is not mapped by name, i.e. "/" or "*.html", then the resulting path will contain the context path only.


fromRequest

public static ServletUriComponentsBuilder fromRequest(HttpServletRequest request)
Return a builder initialized with all available information in the given request including scheme, host, port, path, and query string.


fromCurrentContextPath

public static ServletUriComponentsBuilder fromCurrentContextPath()
Equivalent to fromContextPath(HttpServletRequest) except the request is obtained via RequestContextHolder.


fromCurrentServletMapping

public static ServletUriComponentsBuilder fromCurrentServletMapping()
Equivalent to fromServletMapping(HttpServletRequest) except the request is obtained via RequestContextHolder.


fromCurrentRequest

public static ServletUriComponentsBuilder fromCurrentRequest()
Equivalent to fromRequest(HttpServletRequest) except the request is obtained via RequestContextHolder.