public final class ServletUtil extends Object
Modifier and Type | Method | Description |
---|---|---|
static Map<String,String> |
asMap(javax.servlet.FilterConfig pConfig) |
Creates an unmodifiable
Map view of the given
FilterConfig s init-parameters. |
static Map<String,String> |
asMap(javax.servlet.ServletConfig pConfig) |
Creates an unmodifiable
Map view of the given
ServletConfig s init-parameters. |
static Map<String,Object> |
attributesAsMap(javax.servlet.ServletContext pContext) |
Creates an modifiable
Map view of the given
ServletContext s attributes. |
static Map<String,Object> |
attributesAsMap(javax.servlet.ServletRequest pRequest) |
Creates an modifiable
Map view of the given
ServletRequest s attributes. |
static javax.servlet.ServletRequest |
createWrapper(javax.servlet.ServletRequestWrapper pImplementation) |
Creates a wrapper that implements either
ServletRequest or
HttpServletRequest , depending on the type of
pImplementation.getRequest() . |
static javax.servlet.ServletResponse |
createWrapper(javax.servlet.ServletResponseWrapper pImplementation) |
Creates a wrapper that implements either
ServletResponse or
HttpServletResponse , depending on the type of
pImplementation.getResponse() . |
static boolean |
getBooleanParameter(javax.servlet.ServletRequest pReq,
String pName,
boolean pDefault) |
Gets the value of the given parameter from the request converted to
a
boolean . If the parameter is not set or not parseable, the default
value is returned. |
static String |
getContextRelativeURI(javax.servlet.http.HttpServletRequest pRequest) |
Gets the request URI relative to the current context path.
|
static long |
getDateParameter(javax.servlet.ServletRequest pReq,
String pName,
long pDefault) |
Gets the value of the given parameter from the request converted to
a
Date . If the parameter is not set or not parseable, the
default value is returned. |
static double |
getDoubleParameter(javax.servlet.ServletRequest pReq,
String pName,
double pDefault) |
Gets the value of the given parameter from the request converted to
a
double . If the parameter is not set or not parseable, the default
value is returned. |
static float |
getFloatParameter(javax.servlet.ServletRequest pReq,
String pName,
float pDefault) |
Gets the value of the given parameter from the request converted to
a
float . If the parameter is not set or not parseable, the default
value is returned. |
static String |
getForwardContextPath(javax.servlet.ServletRequest pRequest) |
Gets the context path of the resource this request was forwarded from.
|
static String |
getForwardPathInfo(javax.servlet.ServletRequest pRequest) |
Gets the path info of the resource this request was forwarded from.
|
static String |
getForwardQueryString(javax.servlet.ServletRequest pRequest) |
Gets the query string of the resource this request was forwarded from.
|
static String |
getForwardRequestURI(javax.servlet.ServletRequest pRequest) |
Gets the URI of the resource this request was forwarded from.
|
static String |
getForwardServletPath(javax.servlet.ServletRequest pRequest) |
Gets the servlet path of the resource this request was forwarded from.
|
static String |
getIncludeContextPath(javax.servlet.ServletRequest pRequest) |
Gets the context path of the resource currently included.
|
static String |
getIncludePathInfo(javax.servlet.ServletRequest pRequest) |
Gets the path info of the resource currently included.
|
static String |
getIncludeQueryString(javax.servlet.ServletRequest pRequest) |
Gets the query string of the resource currently included.
|
static String |
getIncludeRequestURI(javax.servlet.ServletRequest pRequest) |
Gets the URI of the resource currently included.
|
static String |
getIncludeServletPath(javax.servlet.ServletRequest pRequest) |
Gets the servlet path of the resource currently included.
|
static int |
getIntParameter(javax.servlet.ServletRequest pReq,
String pName,
int pDefault) |
Gets the value of the given parameter from the request converted to
an
int . If the parameter is not set or not parseable, the default
value is returned. |
static long |
getLongParameter(javax.servlet.ServletRequest pReq,
String pName,
long pDefault) |
Gets the value of the given parameter from the request converted to
an
long . If the parameter is not set or not parseable, the default
value is returned. |
static String |
getParameter(javax.servlet.ServletRequest pReq,
String pName,
String pDefault) |
Gets the value of the given parameter from the request, or if the
parameter is not set, the default value.
|
static URL |
getRealURL(javax.servlet.ServletContext pContext,
String pPath) |
Returns a
URL containing the real path for a given virtual
path, on URL form. |
static String |
getSessionId(javax.servlet.http.HttpServletRequest pRequest) |
Gets the unique identifier assigned to this session.
|
static File |
getTempDir(javax.servlet.ServletContext pContext) |
Gets the temp directory for the given
ServletContext (web app). |
static Map<String,List<String>> |
headersAsMap(javax.servlet.http.HttpServletRequest pRequest) |
Creates an unmodifiable
Map view of the given
HttpServletRequest s request headers. |
static Map<String,String> |
initParamsAsMap(javax.servlet.ServletContext pContext) |
Creates an unmodifiable
Map view of the given
ServletContext s init-parameters. |
static Map<String,List<String>> |
parametersAsMap(javax.servlet.ServletRequest pRequest) |
Creates an unmodifiable
Map view of the given
HttpServletRequest s request parameters. |
public static String getParameter(javax.servlet.ServletRequest pReq, String pName, String pDefault)
pReq
- the servlet requestpName
- the parameter namepDefault
- the default valuepublic static boolean getBooleanParameter(javax.servlet.ServletRequest pReq, String pName, boolean pDefault)
boolean
. If the parameter is not set or not parseable, the default
value is returned.pReq
- the servlet requestpName
- the parameter namepDefault
- the default valueboolean
, or the
default value, if the parameter is not set.public static int getIntParameter(javax.servlet.ServletRequest pReq, String pName, int pDefault)
int
. If the parameter is not set or not parseable, the default
value is returned.pReq
- the servlet requestpName
- the parameter namepDefault
- the default valueint
, or the default
value, if the parameter is not set.public static long getLongParameter(javax.servlet.ServletRequest pReq, String pName, long pDefault)
long
. If the parameter is not set or not parseable, the default
value is returned.pReq
- the servlet requestpName
- the parameter namepDefault
- the default valuelong
, or the default
value, if the parameter is not set.public static float getFloatParameter(javax.servlet.ServletRequest pReq, String pName, float pDefault)
float
. If the parameter is not set or not parseable, the default
value is returned.pReq
- the servlet requestpName
- the parameter namepDefault
- the default valuefloat
, or the default
value, if the parameter is not set.public static double getDoubleParameter(javax.servlet.ServletRequest pReq, String pName, double pDefault)
double
. If the parameter is not set or not parseable, the default
value is returned.pReq
- the servlet requestpName
- the parameter namepDefault
- the default valuedouble
, or the default
value, if the parameter is not set.public static long getDateParameter(javax.servlet.ServletRequest pReq, String pName, long pDefault)
Date
. If the parameter is not set or not parseable, the
default value is returned.pReq
- the servlet requestpName
- the parameter namepDefault
- the default valueDate
, or the
default value, if the parameter is not set.StringUtil.toDate(String)
public static String getIncludeRequestURI(javax.servlet.ServletRequest pRequest)
"javax.servlet.include.request_uri"
pRequest
- the servlet requestnull
if no includeHttpServletRequest.getRequestURI()
public static String getIncludeContextPath(javax.servlet.ServletRequest pRequest)
"javax.servlet.include.context_path"
pRequest
- the servlet requestnull
if no includeHttpServletRequest.getContextPath()
public static String getIncludeServletPath(javax.servlet.ServletRequest pRequest)
"javax.servlet.include.servlet_path"
pRequest
- the servlet requestnull
if no includeHttpServletRequest.getServletPath()
public static String getIncludePathInfo(javax.servlet.ServletRequest pRequest)
"javax.servlet.include.path_info"
pRequest
- the servlet requestnull
if no includeHttpServletRequest.getPathInfo()
public static String getIncludeQueryString(javax.servlet.ServletRequest pRequest)
"javax.servlet.include.query_string"
pRequest
- the servlet requestnull
if no includeHttpServletRequest.getQueryString()
public static String getForwardRequestURI(javax.servlet.ServletRequest pRequest)
"javax.servlet.forward.request_uri"
pRequest
- the servlet requestnull
if not forwardedHttpServletRequest.getRequestURI()
public static String getForwardContextPath(javax.servlet.ServletRequest pRequest)
"javax.servlet.forward.context_path"
pRequest
- the servlet requestnull
if not forwardedHttpServletRequest.getContextPath()
public static String getForwardServletPath(javax.servlet.ServletRequest pRequest)
"javax.servlet.forward.servlet_path"
pRequest
- the servlet requestnull
if not forwardedHttpServletRequest.getServletPath()
public static String getForwardPathInfo(javax.servlet.ServletRequest pRequest)
"javax.servlet.forward.path_info"
pRequest
- the servlet requestnull
if not forwardedHttpServletRequest.getPathInfo()
public static String getForwardQueryString(javax.servlet.ServletRequest pRequest)
"javax.servlet.forward.query_string"
pRequest
- the servlet requestnull
if not forwardedHttpServletRequest.getQueryString()
public static String getContextRelativeURI(javax.servlet.http.HttpServletRequest pRequest)
requestURI = "/webapp/index.jsp" contextPath = "/webapp"The method will return
"/index.jsp"
.pRequest
- the current HTTP requestpublic static URL getRealURL(javax.servlet.ServletContext pContext, String pPath) throws MalformedURLException
URL
containing the real path for a given virtual
path, on URL form.
Note that this method will return null
for all the same reasons
as ServletContext.getRealPath(java.lang.String)
does.pContext
- the servlet contextpPath
- the virtual pathURL
object containing the path, or null
.MalformedURLException
- if the path refers to a malformed URLServletContext.getRealPath(java.lang.String)
,
ServletContext.getResource(java.lang.String)
public static File getTempDir(javax.servlet.ServletContext pContext)
ServletContext
(web app).pContext
- the servlet contextpublic static String getSessionId(javax.servlet.http.HttpServletRequest pRequest)
pRequest
- The HTTP servlet request object.public static Map<String,String> asMap(javax.servlet.ServletConfig pConfig)
Map
view of the given
ServletConfig
s init-parameters.
Note: The returned Map
is optimized for get
operations and iterating over it's keySet
.
For other operations it may not perform well.pConfig
- the servlet configurationMap
view of the configIllegalArgumentException
- if pConfig
is null
public static Map<String,String> asMap(javax.servlet.FilterConfig pConfig)
Map
view of the given
FilterConfig
s init-parameters.
Note: The returned Map
is optimized for get
operations and iterating over it's keySet
.
For other operations it may not perform well.pConfig
- the servlet filter configurationMap
view of the configIllegalArgumentException
- if pConfig
is null
public static Map<String,String> initParamsAsMap(javax.servlet.ServletContext pContext)
Map
view of the given
ServletContext
s init-parameters.
Note: The returned Map
is optimized for get
operations and iterating over it's keySet
.
For other operations it may not perform well.pContext
- the servlet contextMap
view of the init parametersIllegalArgumentException
- if pContext
is null
public static Map<String,Object> attributesAsMap(javax.servlet.ServletContext pContext)
Map
view of the given
ServletContext
s attributes.pContext
- the servlet contextMap
view of the attributesIllegalArgumentException
- if pContext
is null
public static Map<String,Object> attributesAsMap(javax.servlet.ServletRequest pRequest)
Map
view of the given
ServletRequest
s attributes.pRequest
- the servlet requestMap
view of the attributesIllegalArgumentException
- if pContext
is null
public static Map<String,List<String>> parametersAsMap(javax.servlet.ServletRequest pRequest)
Map
view of the given
HttpServletRequest
s request parameters.pRequest
- the requestMap
view of the request parametersIllegalArgumentException
- if pRequest
is null
public static Map<String,List<String>> headersAsMap(javax.servlet.http.HttpServletRequest pRequest)
Map
view of the given
HttpServletRequest
s request headers.pRequest
- the requestMap
view of the request headersIllegalArgumentException
- if pRequest
is null
public static javax.servlet.ServletResponse createWrapper(javax.servlet.ServletResponseWrapper pImplementation)
ServletResponse
or
HttpServletResponse
, depending on the type of
pImplementation.getResponse()
.pImplementation
- the servlet response to create a wrapper forServletResponse
or
HttpServletResponse
, depending on the type of
pImplementation.getResponse()
public static javax.servlet.ServletRequest createWrapper(javax.servlet.ServletRequestWrapper pImplementation)
ServletRequest
or
HttpServletRequest
, depending on the type of
pImplementation.getRequest()
.pImplementation
- the servlet request to create a wrapper forServletResponse
or
HttpServletResponse
, depending on the type of
pImplementation.getResponse()
Copyright © 2018. All rights reserved.