public final class Servlets extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
getApplicationAttribute(ServletContext context,
String name)
Returns the application scope attribute value associated with the given name.
|
static String |
getForwardRequestQueryString(HttpServletRequest request)
Returns the original HTTP request query string behind this forwarded request, if any.
|
static String |
getForwardRequestURI(HttpServletRequest request)
Returns the original HTTP request URI behind this forwarded request, if any.
|
static String |
getForwardRequestURIWithQueryString(HttpServletRequest request)
Returns the original HTTP request URI with query string behind this forwarded request, if any.
|
static String |
getRequestBaseURL(HttpServletRequest request)
Returns the HTTP request base URL.
|
static String |
getRequestDomainURL(HttpServletRequest request)
Returns the HTTP request domain URL.
|
static String |
getRequestHostname(HttpServletRequest request)
Returns the HTTP request hostname.
|
static Map<String,List<String>> |
getRequestQueryStringMap(HttpServletRequest request)
Returns the HTTP request query string as parameter values map.
|
static String |
getRequestRelativeURI(HttpServletRequest request)
Returns the HTTP request URI relative to the context root of a web application.
|
static String |
getRequestRelativeURIWithoutPathParameters(HttpServletRequest request)
Returns the HTTP request URI relative to the context root of a web application.
|
static String |
getRequestURIWithQueryString(HttpServletRequest request)
Returns the HTTP request URI with query string.
|
static String |
getRequestURLWithQueryString(HttpServletRequest request)
Returns the HTTP request URL with query string.
|
static Map<String,List<String>> |
toParameterMap(String queryString)
Converts the given query string to request parameter values map.
|
public static String getRequestHostname(HttpServletRequest request)
ServletRequest.getServerName() as its
outcome can be influenced by proxies.request - The involved HTTP servlet request.IllegalArgumentException - When the URL is malformed. This is however unexpected as the request would
otherwise not have hit the server at all.HttpServletRequest.getRequestURL()public static String getRequestDomainURL(HttpServletRequest request)
request - The involved HTTP servlet request.HttpServletRequest.getRequestURL(),
HttpServletRequest.getRequestURI()public static String getRequestBaseURL(HttpServletRequest request)
<base> tag.request - The involved HTTP servlet request.HttpServletRequest.getRequestURL(),
HttpServletRequest.getRequestURI(),
HttpServletRequest.getContextPath()public static String getRequestRelativeURI(HttpServletRequest request)
request - The involved HTTP servlet request.public static String getRequestRelativeURIWithoutPathParameters(HttpServletRequest request)
request - The involved HTTP servlet request.public static String getRequestURLWithQueryString(HttpServletRequest request)
request - The involved HTTP servlet request.HttpServletRequest.getRequestURL(),
HttpServletRequest.getQueryString()public static String getRequestURIWithQueryString(HttpServletRequest request)
request - The involved HTTP servlet request.HttpServletRequest.getRequestURI(),
HttpServletRequest.getQueryString()public static Map<String,List<String>> getRequestQueryStringMap(HttpServletRequest request)
ServletRequest.getParameterMap(), which contains both
the request URL (GET) parameters and and the request body (POST) parameters.
The map entries are in the same order as they appear in the query string.request - The request for which the base URL is computed.public static String getForwardRequestURI(HttpServletRequest request)
public static String getForwardRequestQueryString(HttpServletRequest request)
public static String getForwardRequestURIWithQueryString(HttpServletRequest request)
public static Map<String,List<String>> toParameterMap(String queryString)
queryString - The query string.public static <T> T getApplicationAttribute(ServletContext context, String name)
context - The servlet context used for looking up the attribute.name - The application scope attribute name.ClassCastException - When T is of wrong type.ServletContext.getAttribute(String)