org.clazzes.util.http
public abstract class RequestHelper extends Object
Constructor and Description |
---|
RequestHelper() |
Modifier and Type | Method and Description |
---|---|
static Boolean |
getBooleanParameter(javax.servlet.http.HttpServletRequest req,
String key)
Get the value of the servlet parameter
key and parse it
using Boolean.parseBoolean(String) if a value for this servlet parameter
has been found. |
static Double |
getDoubleParameter(javax.servlet.http.HttpServletRequest req,
String key)
Get the value of the servlet parameter
key and parse it
using Double.parseDouble(String) if a value for this servlet parameter
has been found. |
static Integer |
getIntegerParameter(javax.servlet.http.HttpServletRequest req,
String key)
Get the value of the servlet parameter
key and parse it
using Integer.parseInt(String) if a value for this servlet parameter
has been found. |
static Long |
getLongParameter(javax.servlet.http.HttpServletRequest req,
String key)
Get the value of the servlet parameter
key and parse it
using Long.parseLong(String) if a value for this servlet parameter
has been found. |
static String |
getRealRemoteIP(javax.servlet.http.HttpServletRequest request)
Get the remote IP address of the client taking the
X-Forwarded-for header into account. |
static String |
getResolvedPath(javax.servlet.http.HttpServletRequest req)
Get the server-side path which may have been resolved by a delegating
servlet.
|
static void |
setResolvedPath(javax.servlet.http.HttpServletRequest req,
String resolvedPath) |
public static void setResolvedPath(javax.servlet.http.HttpServletRequest req, String resolvedPath)
req
- The request to inform about path resolution.resolvedPath
- The resolved server-side path to be propagted to a delegate
servlet.public static String getResolvedPath(javax.servlet.http.HttpServletRequest req)
req
- The request to query.RESOLVED_PATH_ATTR
attribute
or The result of HttpServletRequest.getPathInfo()
, if
no such attribute is present.public static String getRealRemoteIP(javax.servlet.http.HttpServletRequest request)
Get the remote IP address of the client taking the
X-Forwarded-for
header into account.
If no X-Forwarded-for
header is present,
the value of ServletRequest.getRemoteAddr()
is returned.
If a X-Forwarded-for
header is present,
the leftmost value in the comma-separated list of
X-Forwarded-for
-addresses is returned.
The rationale for returning the leftmost address is, that
this is the original address of the client.
request
- A HTTP servlet request.public static Double getDoubleParameter(javax.servlet.http.HttpServletRequest req, String key) throws NumberFormatException
Get the value of the servlet parameter key
and parse it
using Double.parseDouble(String)
if a value for this servlet parameter
has been found.
Warning:
For POST requests with a Content-Type application/x-www-form-urlencoded
this method triggers a parsing of the all posted query parameters.
To avoid this, use UrlHelper.parseQuery(String)
together with
UrlHelper.getDoubleParameter(java.util.Map, String)
.
req
- The HTTP servlet request to query.key
- The key of the double parameter to parse.null
if no request parameter with name key
is given.NumberFormatException
- If the value of the servlet parameter is
not a double value as per Double.parseDouble(String)
.public static Long getLongParameter(javax.servlet.http.HttpServletRequest req, String key) throws NumberFormatException
Get the value of the servlet parameter key
and parse it
using Long.parseLong(String)
if a value for this servlet parameter
has been found.
Warning:
For POST requests with a Content-Type application/x-www-form-urlencoded
this method triggers a parsing of the all posted query parameters.
To avoid this, use UrlHelper.parseQuery(String)
together with
UrlHelper.getLongParameter(java.util.Map, String)
.
req
- The HTTP servlet request to query.key
- The key of the long parameter to parse.null
if no request parameter with name key
is given.NumberFormatException
- If the value of the servlet parameter is
not a long value as per Long.parseLong(String)
.public static Integer getIntegerParameter(javax.servlet.http.HttpServletRequest req, String key) throws NumberFormatException
Get the value of the servlet parameter key
and parse it
using Integer.parseInt(String)
if a value for this servlet parameter
has been found.
Warning:
For POST requests with a Content-Type application/x-www-form-urlencoded
this method triggers a parsing of the all posted query parameters.
To avoid this, use UrlHelper.parseQuery(String)
together with
UrlHelper.getIntegerParameter(java.util.Map, String)
.
req
- The HTTP servlet request to query.key
- The key of the integer parameter to parse.null
if no request parameter with name key
is given.NumberFormatException
- If the value of the servlet parameter is
not an integer value as per Integer.parseInt(String)
.public static Boolean getBooleanParameter(javax.servlet.http.HttpServletRequest req, String key)
Get the value of the servlet parameter key
and parse it
using Boolean.parseBoolean(String)
if a value for this servlet parameter
has been found.
Warning:
For POST requests with a Content-Type application/x-www-form-urlencoded
this method triggers a parsing of the all posted query parameters.
To avoid this, use UrlHelper.parseQuery(String)
together with
UrlHelper.getBooleanParameter(java.util.Map, String)
.
req
- The HTTP servlet request to query.key
- The key of the boolean parameter to parse.null
if no request parameter with name key
is given.NumberFormatException
- If the value of the servlet parameter is
not an integer value as per Boolean.parseBoolean(String)
.Copyright © 2013 Clazzes.org. All Rights Reserved.