Package com.twelvemonkeys.servlet
Class ServletUtil
- java.lang.Object
-
- com.twelvemonkeys.servlet.ServletUtil
-
@Deprecated public final class ServletUtil extends java.lang.Object
Deprecated.Various servlet related helper methods.- Version:
- $Id: ServletUtil.java#3 $
- Author:
- Harald Kuhr, Eirik Torske, last modified by $Author: haku $
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.util.Map<java.lang.String,java.lang.String>
asMap(javax.servlet.FilterConfig pConfig)
Deprecated.Creates an unmodifiableMap
view of the givenFilterConfig
s init-parameters.static java.util.Map<java.lang.String,java.lang.String>
asMap(javax.servlet.ServletConfig pConfig)
Deprecated.Creates an unmodifiableMap
view of the givenServletConfig
s init-parameters.static java.util.Map<java.lang.String,java.lang.Object>
attributesAsMap(javax.servlet.ServletContext pContext)
Deprecated.Creates an modifiableMap
view of the givenServletContext
s attributes.static java.util.Map<java.lang.String,java.lang.Object>
attributesAsMap(javax.servlet.ServletRequest pRequest)
Deprecated.Creates an modifiableMap
view of the givenServletRequest
s attributes.static javax.servlet.ServletRequest
createWrapper(javax.servlet.ServletRequestWrapper pImplementation)
Deprecated.Creates a wrapper that implements eitherServletRequest
orHttpServletRequest
, depending on the type ofpImplementation.getRequest()
.static javax.servlet.ServletResponse
createWrapper(javax.servlet.ServletResponseWrapper pImplementation)
Deprecated.Creates a wrapper that implements eitherServletResponse
orHttpServletResponse
, depending on the type ofpImplementation.getResponse()
.static boolean
getBooleanParameter(javax.servlet.ServletRequest pReq, java.lang.String pName, boolean pDefault)
Deprecated.Gets the value of the given parameter from the request converted to aboolean
. If the parameter is not set or not parseable, the default value is returned.static java.lang.String
getContextRelativeURI(javax.servlet.http.HttpServletRequest pRequest)
Deprecated.Gets the request URI relative to the current context path.static long
getDateParameter(javax.servlet.ServletRequest pReq, java.lang.String pName, long pDefault)
Deprecated.Gets the value of the given parameter from the request converted to aDate
. If the parameter is not set or not parseable, the default value is returned.static double
getDoubleParameter(javax.servlet.ServletRequest pReq, java.lang.String pName, double pDefault)
Deprecated.Gets the value of the given parameter from the request converted to adouble
. If the parameter is not set or not parseable, the default value is returned.static float
getFloatParameter(javax.servlet.ServletRequest pReq, java.lang.String pName, float pDefault)
Deprecated.Gets the value of the given parameter from the request converted to afloat
. If the parameter is not set or not parseable, the default value is returned.static java.lang.String
getForwardContextPath(javax.servlet.ServletRequest pRequest)
Deprecated.Gets the context path of the resource this request was forwarded from.static java.lang.String
getForwardPathInfo(javax.servlet.ServletRequest pRequest)
Deprecated.Gets the path info of the resource this request was forwarded from.static java.lang.String
getForwardQueryString(javax.servlet.ServletRequest pRequest)
Deprecated.Gets the query string of the resource this request was forwarded from.static java.lang.String
getForwardRequestURI(javax.servlet.ServletRequest pRequest)
Deprecated.Gets the URI of the resource this request was forwarded from.static java.lang.String
getForwardServletPath(javax.servlet.ServletRequest pRequest)
Deprecated.Gets the servlet path of the resource this request was forwarded from.static java.lang.String
getIncludeContextPath(javax.servlet.ServletRequest pRequest)
Deprecated.Gets the context path of the resource currently included.static java.lang.String
getIncludePathInfo(javax.servlet.ServletRequest pRequest)
Deprecated.Gets the path info of the resource currently included.static java.lang.String
getIncludeQueryString(javax.servlet.ServletRequest pRequest)
Deprecated.Gets the query string of the resource currently included.static java.lang.String
getIncludeRequestURI(javax.servlet.ServletRequest pRequest)
Deprecated.Gets the URI of the resource currently included.static java.lang.String
getIncludeServletPath(javax.servlet.ServletRequest pRequest)
Deprecated.Gets the servlet path of the resource currently included.static int
getIntParameter(javax.servlet.ServletRequest pReq, java.lang.String pName, int pDefault)
Deprecated.Gets the value of the given parameter from the request converted to anint
. If the parameter is not set or not parseable, the default value is returned.static long
getLongParameter(javax.servlet.ServletRequest pReq, java.lang.String pName, long pDefault)
Deprecated.Gets the value of the given parameter from the request converted to anlong
. If the parameter is not set or not parseable, the default value is returned.static java.lang.String
getParameter(javax.servlet.ServletRequest pReq, java.lang.String pName, java.lang.String pDefault)
Deprecated.Gets the value of the given parameter from the request, or if the parameter is not set, the default value.static java.net.URL
getRealURL(javax.servlet.ServletContext pContext, java.lang.String pPath)
Deprecated.Returns aURL
containing the real path for a given virtual path, on URL form.static java.lang.String
getSessionId(javax.servlet.http.HttpServletRequest pRequest)
Deprecated.Gets the unique identifier assigned to this session.static java.io.File
getTempDir(javax.servlet.ServletContext pContext)
Deprecated.Gets the temp directory for the givenServletContext
(web app).static java.util.Map<java.lang.String,java.util.List<java.lang.String>>
headersAsMap(javax.servlet.http.HttpServletRequest pRequest)
Deprecated.Creates an unmodifiableMap
view of the givenHttpServletRequest
s request headers.static java.util.Map<java.lang.String,java.lang.String>
initParamsAsMap(javax.servlet.ServletContext pContext)
Deprecated.Creates an unmodifiableMap
view of the givenServletContext
s init-parameters.static java.util.Map<java.lang.String,java.util.List<java.lang.String>>
parametersAsMap(javax.servlet.ServletRequest pRequest)
Deprecated.Creates an unmodifiableMap
view of the givenHttpServletRequest
s request parameters.
-
-
-
Method Detail
-
getParameter
public static java.lang.String getParameter(javax.servlet.ServletRequest pReq, java.lang.String pName, java.lang.String pDefault)
Deprecated.Gets the value of the given parameter from the request, or if the parameter is not set, the default value.- Parameters:
pReq
- the servlet requestpName
- the parameter namepDefault
- the default value- Returns:
- the value of the parameter, or the default value, if the parameter is not set.
-
getBooleanParameter
public static boolean getBooleanParameter(javax.servlet.ServletRequest pReq, java.lang.String pName, boolean pDefault)
Deprecated.Gets the value of the given parameter from the request converted to aboolean
. If the parameter is not set or not parseable, the default value is returned.- Parameters:
pReq
- the servlet requestpName
- the parameter namepDefault
- the default value- Returns:
- the value of the parameter converted to a
boolean
, or the default value, if the parameter is not set.
-
getIntParameter
public static int getIntParameter(javax.servlet.ServletRequest pReq, java.lang.String pName, int pDefault)
Deprecated.Gets the value of the given parameter from the request converted to anint
. If the parameter is not set or not parseable, the default value is returned.- Parameters:
pReq
- the servlet requestpName
- the parameter namepDefault
- the default value- Returns:
- the value of the parameter converted to an
int
, or the default value, if the parameter is not set.
-
getLongParameter
public static long getLongParameter(javax.servlet.ServletRequest pReq, java.lang.String pName, long pDefault)
Deprecated.Gets the value of the given parameter from the request converted to anlong
. If the parameter is not set or not parseable, the default value is returned.- Parameters:
pReq
- the servlet requestpName
- the parameter namepDefault
- the default value- Returns:
- the value of the parameter converted to an
long
, or the default value, if the parameter is not set.
-
getFloatParameter
public static float getFloatParameter(javax.servlet.ServletRequest pReq, java.lang.String pName, float pDefault)
Deprecated.Gets the value of the given parameter from the request converted to afloat
. If the parameter is not set or not parseable, the default value is returned.- Parameters:
pReq
- the servlet requestpName
- the parameter namepDefault
- the default value- Returns:
- the value of the parameter converted to a
float
, or the default value, if the parameter is not set.
-
getDoubleParameter
public static double getDoubleParameter(javax.servlet.ServletRequest pReq, java.lang.String pName, double pDefault)
Deprecated.Gets the value of the given parameter from the request converted to adouble
. If the parameter is not set or not parseable, the default value is returned.- Parameters:
pReq
- the servlet requestpName
- the parameter namepDefault
- the default value- Returns:
- the value of the parameter converted to n
double
, or the default value, if the parameter is not set.
-
getDateParameter
public static long getDateParameter(javax.servlet.ServletRequest pReq, java.lang.String pName, long pDefault)
Deprecated.Gets the value of the given parameter from the request converted to aDate
. If the parameter is not set or not parseable, the default value is returned.- Parameters:
pReq
- the servlet requestpName
- the parameter namepDefault
- the default value- Returns:
- the value of the parameter converted to a
Date
, or the default value, if the parameter is not set. - See Also:
StringUtil.toDate(String)
-
getIncludeRequestURI
public static java.lang.String getIncludeRequestURI(javax.servlet.ServletRequest pRequest)
Deprecated.Gets the URI of the resource currently included. The value is read from the request attribute"javax.servlet.include.request_uri"
- Parameters:
pRequest
- the servlet request- Returns:
- the URI of the included resource, or
null
if no include - Since:
- Servlet 2.2
- See Also:
HttpServletRequest.getRequestURI()
-
getIncludeContextPath
public static java.lang.String getIncludeContextPath(javax.servlet.ServletRequest pRequest)
Deprecated.Gets the context path of the resource currently included. The value is read from the request attribute"javax.servlet.include.context_path"
- Parameters:
pRequest
- the servlet request- Returns:
- the context path of the included resource, or
null
if no include - Since:
- Servlet 2.2
- See Also:
HttpServletRequest.getContextPath()
-
getIncludeServletPath
public static java.lang.String getIncludeServletPath(javax.servlet.ServletRequest pRequest)
Deprecated.Gets the servlet path of the resource currently included. The value is read from the request attribute"javax.servlet.include.servlet_path"
- Parameters:
pRequest
- the servlet request- Returns:
- the servlet path of the included resource, or
null
if no include - Since:
- Servlet 2.2
- See Also:
HttpServletRequest.getServletPath()
-
getIncludePathInfo
public static java.lang.String getIncludePathInfo(javax.servlet.ServletRequest pRequest)
Deprecated.Gets the path info of the resource currently included. The value is read from the request attribute"javax.servlet.include.path_info"
- Parameters:
pRequest
- the servlet request- Returns:
- the path info of the included resource, or
null
if no include - Since:
- Servlet 2.2
- See Also:
HttpServletRequest.getPathInfo()
-
getIncludeQueryString
public static java.lang.String getIncludeQueryString(javax.servlet.ServletRequest pRequest)
Deprecated.Gets the query string of the resource currently included. The value is read from the request attribute"javax.servlet.include.query_string"
- Parameters:
pRequest
- the servlet request- Returns:
- the query string of the included resource, or
null
if no include - Since:
- Servlet 2.2
- See Also:
HttpServletRequest.getQueryString()
-
getForwardRequestURI
public static java.lang.String getForwardRequestURI(javax.servlet.ServletRequest pRequest)
Deprecated.Gets the URI of the resource this request was forwarded from. The value is read from the request attribute"javax.servlet.forward.request_uri"
- Parameters:
pRequest
- the servlet request- Returns:
- the URI of the resource, or
null
if not forwarded - Since:
- Servlet 2.4
- See Also:
HttpServletRequest.getRequestURI()
-
getForwardContextPath
public static java.lang.String getForwardContextPath(javax.servlet.ServletRequest pRequest)
Deprecated.Gets the context path of the resource this request was forwarded from. The value is read from the request attribute"javax.servlet.forward.context_path"
- Parameters:
pRequest
- the servlet request- Returns:
- the context path of the resource, or
null
if not forwarded - Since:
- Servlet 2.4
- See Also:
HttpServletRequest.getContextPath()
-
getForwardServletPath
public static java.lang.String getForwardServletPath(javax.servlet.ServletRequest pRequest)
Deprecated.Gets the servlet path of the resource this request was forwarded from. The value is read from the request attribute"javax.servlet.forward.servlet_path"
- Parameters:
pRequest
- the servlet request- Returns:
- the servlet path of the resource, or
null
if not forwarded - Since:
- Servlet 2.4
- See Also:
HttpServletRequest.getServletPath()
-
getForwardPathInfo
public static java.lang.String getForwardPathInfo(javax.servlet.ServletRequest pRequest)
Deprecated.Gets the path info of the resource this request was forwarded from. The value is read from the request attribute"javax.servlet.forward.path_info"
- Parameters:
pRequest
- the servlet request- Returns:
- the path info of the resource, or
null
if not forwarded - Since:
- Servlet 2.4
- See Also:
HttpServletRequest.getPathInfo()
-
getForwardQueryString
public static java.lang.String getForwardQueryString(javax.servlet.ServletRequest pRequest)
Deprecated.Gets the query string of the resource this request was forwarded from. The value is read from the request attribute"javax.servlet.forward.query_string"
- Parameters:
pRequest
- the servlet request- Returns:
- the query string of the resource, or
null
if not forwarded - Since:
- Servlet 2.4
- See Also:
HttpServletRequest.getQueryString()
-
getContextRelativeURI
public static java.lang.String getContextRelativeURI(javax.servlet.http.HttpServletRequest pRequest)
Deprecated.Gets the request URI relative to the current context path.As an example:
requestURI = "/webapp/index.jsp" contextPath = "/webapp"
The method will return"/index.jsp"
.- Parameters:
pRequest
- the current HTTP request- Returns:
- the request URI relative to the current context path.
-
getRealURL
public static java.net.URL getRealURL(javax.servlet.ServletContext pContext, java.lang.String pPath) throws java.net.MalformedURLException
Deprecated.Returns aURL
containing the real path for a given virtual path, on URL form. Note that this method will returnnull
for all the same reasons asServletContext.getRealPath(java.lang.String)
does.- Parameters:
pContext
- the servlet contextpPath
- the virtual path- Returns:
- a
URL
object containing the path, ornull
. - Throws:
java.net.MalformedURLException
- if the path refers to a malformed URL- See Also:
ServletContext.getRealPath(java.lang.String)
,ServletContext.getResource(java.lang.String)
-
getTempDir
public static java.io.File getTempDir(javax.servlet.ServletContext pContext)
Deprecated.Gets the temp directory for the givenServletContext
(web app).- Parameters:
pContext
- the servlet context- Returns:
- the temp directory
-
getSessionId
public static java.lang.String getSessionId(javax.servlet.http.HttpServletRequest pRequest)
Deprecated.Gets the unique identifier assigned to this session. The identifier is assigned by the servlet container and is implementation dependent.- Parameters:
pRequest
- The HTTP servlet request object.- Returns:
- the session Id
-
asMap
public static java.util.Map<java.lang.String,java.lang.String> asMap(javax.servlet.ServletConfig pConfig)
Deprecated.Creates an unmodifiableMap
view of the givenServletConfig
s init-parameters. Note: The returnedMap
is optimized forget
operations and iterating over it'skeySet
. For other operations it may not perform well.- Parameters:
pConfig
- the servlet configuration- Returns:
- a
Map
view of the config - Throws:
java.lang.IllegalArgumentException
- ifpConfig
isnull
-
asMap
public static java.util.Map<java.lang.String,java.lang.String> asMap(javax.servlet.FilterConfig pConfig)
Deprecated.Creates an unmodifiableMap
view of the givenFilterConfig
s init-parameters. Note: The returnedMap
is optimized forget
operations and iterating over it'skeySet
. For other operations it may not perform well.- Parameters:
pConfig
- the servlet filter configuration- Returns:
- a
Map
view of the config - Throws:
java.lang.IllegalArgumentException
- ifpConfig
isnull
-
initParamsAsMap
public static java.util.Map<java.lang.String,java.lang.String> initParamsAsMap(javax.servlet.ServletContext pContext)
Deprecated.Creates an unmodifiableMap
view of the givenServletContext
s init-parameters. Note: The returnedMap
is optimized forget
operations and iterating over it'skeySet
. For other operations it may not perform well.- Parameters:
pContext
- the servlet context- Returns:
- a
Map
view of the init parameters - Throws:
java.lang.IllegalArgumentException
- ifpContext
isnull
-
attributesAsMap
public static java.util.Map<java.lang.String,java.lang.Object> attributesAsMap(javax.servlet.ServletContext pContext)
Deprecated.Creates an modifiableMap
view of the givenServletContext
s attributes.- Parameters:
pContext
- the servlet context- Returns:
- a
Map
view of the attributes - Throws:
java.lang.IllegalArgumentException
- ifpContext
isnull
-
attributesAsMap
public static java.util.Map<java.lang.String,java.lang.Object> attributesAsMap(javax.servlet.ServletRequest pRequest)
Deprecated.Creates an modifiableMap
view of the givenServletRequest
s attributes.- Parameters:
pRequest
- the servlet request- Returns:
- a
Map
view of the attributes - Throws:
java.lang.IllegalArgumentException
- ifpContext
isnull
-
parametersAsMap
public static java.util.Map<java.lang.String,java.util.List<java.lang.String>> parametersAsMap(javax.servlet.ServletRequest pRequest)
Deprecated.Creates an unmodifiableMap
view of the givenHttpServletRequest
s request parameters.- Parameters:
pRequest
- the request- Returns:
- a
Map
view of the request parameters - Throws:
java.lang.IllegalArgumentException
- ifpRequest
isnull
-
headersAsMap
public static java.util.Map<java.lang.String,java.util.List<java.lang.String>> headersAsMap(javax.servlet.http.HttpServletRequest pRequest)
Deprecated.Creates an unmodifiableMap
view of the givenHttpServletRequest
s request headers.- Parameters:
pRequest
- the request- Returns:
- a
Map
view of the request headers - Throws:
java.lang.IllegalArgumentException
- ifpRequest
isnull
-
createWrapper
public static javax.servlet.ServletResponse createWrapper(javax.servlet.ServletResponseWrapper pImplementation)
Deprecated.Creates a wrapper that implements eitherServletResponse
orHttpServletResponse
, depending on the type ofpImplementation.getResponse()
.- Parameters:
pImplementation
- the servlet response to create a wrapper for- Returns:
- a
ServletResponse
orHttpServletResponse
, depending on the type ofpImplementation.getResponse()
-
createWrapper
public static javax.servlet.ServletRequest createWrapper(javax.servlet.ServletRequestWrapper pImplementation)
Deprecated.Creates a wrapper that implements eitherServletRequest
orHttpServletRequest
, depending on the type ofpImplementation.getRequest()
.- Parameters:
pImplementation
- the servlet request to create a wrapper for- Returns:
- a
ServletResponse
orHttpServletResponse
, depending on the type ofpImplementation.getResponse()
-
-