public abstract class ServletRequestUtils
extends java.lang.Object
This approach is very useful for simple submissions, where binding request parameters to a command object would be overkill.
Constructor and Description |
---|
ServletRequestUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.Boolean |
getBooleanParameter(ServletRequest request,
java.lang.String name)
Get a Boolean parameter, or
null if not present. |
static boolean |
getBooleanParameter(ServletRequest request,
java.lang.String name,
boolean defaultVal)
Get a boolean parameter, with a fallback value.
|
static boolean[] |
getBooleanParameters(ServletRequest request,
java.lang.String name)
Get an array of boolean parameters, return an empty array if not found.
|
static java.lang.Double |
getDoubleParameter(ServletRequest request,
java.lang.String name)
Get a Double parameter, or
null if not present. |
static double |
getDoubleParameter(ServletRequest request,
java.lang.String name,
double defaultVal)
Get a double parameter, with a fallback value.
|
static double[] |
getDoubleParameters(ServletRequest request,
java.lang.String name)
Get an array of double parameters, return an empty array if not found.
|
static java.lang.Float |
getFloatParameter(ServletRequest request,
java.lang.String name)
Get a Float parameter, or
null if not present. |
static float |
getFloatParameter(ServletRequest request,
java.lang.String name,
float defaultVal)
Get a float parameter, with a fallback value.
|
static float[] |
getFloatParameters(ServletRequest request,
java.lang.String name)
Get an array of float parameters, return an empty array if not found.
|
static java.lang.Integer |
getIntParameter(ServletRequest request,
java.lang.String name)
Get an Integer parameter, or
null if not present. |
static int |
getIntParameter(ServletRequest request,
java.lang.String name,
int defaultVal)
Get an int parameter, with a fallback value.
|
static int[] |
getIntParameters(ServletRequest request,
java.lang.String name)
Get an array of int parameters, return an empty array if not found.
|
static java.lang.Long |
getLongParameter(ServletRequest request,
java.lang.String name)
Get a Long parameter, or
null if not present. |
static long |
getLongParameter(ServletRequest request,
java.lang.String name,
long defaultVal)
Get a long parameter, with a fallback value.
|
static long[] |
getLongParameters(ServletRequest request,
java.lang.String name)
Get an array of long parameters, return an empty array if not found.
|
static boolean |
getRequiredBooleanParameter(ServletRequest request,
java.lang.String name)
Get a boolean parameter, throwing an exception if it isn't found
or isn't a boolean.
|
static boolean[] |
getRequiredBooleanParameters(ServletRequest request,
java.lang.String name)
Get an array of boolean parameters, throwing an exception if not found
or one isn't a boolean.
|
static double |
getRequiredDoubleParameter(ServletRequest request,
java.lang.String name)
Get a double parameter, throwing an exception if it isn't found or isn't a number.
|
static double[] |
getRequiredDoubleParameters(ServletRequest request,
java.lang.String name)
Get an array of double parameters, throwing an exception if not found or one is not a number.
|
static float |
getRequiredFloatParameter(ServletRequest request,
java.lang.String name)
Get a float parameter, throwing an exception if it isn't found or isn't a number.
|
static float[] |
getRequiredFloatParameters(ServletRequest request,
java.lang.String name)
Get an array of float parameters, throwing an exception if not found or one is not a number.
|
static int |
getRequiredIntParameter(ServletRequest request,
java.lang.String name)
Get an int parameter, throwing an exception if it isn't found or isn't a number.
|
static int[] |
getRequiredIntParameters(ServletRequest request,
java.lang.String name)
Get an array of int parameters, throwing an exception if not found or one is not a number..
|
static long |
getRequiredLongParameter(ServletRequest request,
java.lang.String name)
Get a long parameter, throwing an exception if it isn't found or isn't a number.
|
static long[] |
getRequiredLongParameters(ServletRequest request,
java.lang.String name)
Get an array of long parameters, throwing an exception if not found or one is not a number.
|
static java.lang.String |
getRequiredStringParameter(ServletRequest request,
java.lang.String name)
Get a String parameter, throwing an exception if it isn't found.
|
static java.lang.String[] |
getRequiredStringParameters(ServletRequest request,
java.lang.String name)
Get an array of String parameters, throwing an exception if not found.
|
static java.lang.String |
getStringParameter(ServletRequest request,
java.lang.String name)
Get a String parameter, or
null if not present. |
static java.lang.String |
getStringParameter(ServletRequest request,
java.lang.String name,
java.lang.String defaultVal)
Get a String parameter, with a fallback value.
|
static java.lang.String[] |
getStringParameters(ServletRequest request,
java.lang.String name)
Get an array of String parameters, return an empty array if not found.
|
public static java.lang.Integer getIntParameter(ServletRequest request, java.lang.String name) throws ServletRequestBindingException
null
if not present.
Throws an exception if it the parameter value isn't a number.request
- current HTTP requestname
- the name of the parameternull
if not presentServletRequestBindingException
- a subclass of ServletException,
so it doesn't need to be caughtpublic static int getIntParameter(ServletRequest request, java.lang.String name, int defaultVal)
request
- current HTTP requestname
- the name of the parameterdefaultVal
- the default value to use as fallbackpublic static int[] getIntParameters(ServletRequest request, java.lang.String name)
request
- current HTTP requestname
- the name of the parameter with multiple possible valuespublic static int getRequiredIntParameter(ServletRequest request, java.lang.String name) throws ServletRequestBindingException
request
- current HTTP requestname
- the name of the parameterServletRequestBindingException
- a subclass of ServletException,
so it doesn't need to be caughtpublic static int[] getRequiredIntParameters(ServletRequest request, java.lang.String name) throws ServletRequestBindingException
request
- current HTTP requestname
- the name of the parameter with multiple possible valuesServletRequestBindingException
- a subclass of ServletException,
so it doesn't need to be caughtpublic static java.lang.Long getLongParameter(ServletRequest request, java.lang.String name) throws ServletRequestBindingException
null
if not present.
Throws an exception if it the parameter value isn't a number.request
- current HTTP requestname
- the name of the parameternull
if not presentServletRequestBindingException
- a subclass of ServletException,
so it doesn't need to be caughtpublic static long getLongParameter(ServletRequest request, java.lang.String name, long defaultVal)
request
- current HTTP requestname
- the name of the parameterdefaultVal
- the default value to use as fallbackpublic static long[] getLongParameters(ServletRequest request, java.lang.String name)
request
- current HTTP requestname
- the name of the parameter with multiple possible valuespublic static long getRequiredLongParameter(ServletRequest request, java.lang.String name) throws ServletRequestBindingException
request
- current HTTP requestname
- the name of the parameterServletRequestBindingException
- a subclass of ServletException,
so it doesn't need to be caughtpublic static long[] getRequiredLongParameters(ServletRequest request, java.lang.String name) throws ServletRequestBindingException
request
- current HTTP requestname
- the name of the parameter with multiple possible valuesServletRequestBindingException
- a subclass of ServletException,
so it doesn't need to be caughtpublic static java.lang.Float getFloatParameter(ServletRequest request, java.lang.String name) throws ServletRequestBindingException
null
if not present.
Throws an exception if it the parameter value isn't a number.request
- current HTTP requestname
- the name of the parameternull
if not presentServletRequestBindingException
- a subclass of ServletException,
so it doesn't need to be caughtpublic static float getFloatParameter(ServletRequest request, java.lang.String name, float defaultVal)
request
- current HTTP requestname
- the name of the parameterdefaultVal
- the default value to use as fallbackpublic static float[] getFloatParameters(ServletRequest request, java.lang.String name)
request
- current HTTP requestname
- the name of the parameter with multiple possible valuespublic static float getRequiredFloatParameter(ServletRequest request, java.lang.String name) throws ServletRequestBindingException
request
- current HTTP requestname
- the name of the parameterServletRequestBindingException
- a subclass of ServletException,
so it doesn't need to be caughtpublic static float[] getRequiredFloatParameters(ServletRequest request, java.lang.String name) throws ServletRequestBindingException
request
- current HTTP requestname
- the name of the parameter with multiple possible valuesServletRequestBindingException
- a subclass of ServletException,
so it doesn't need to be caughtpublic static java.lang.Double getDoubleParameter(ServletRequest request, java.lang.String name) throws ServletRequestBindingException
null
if not present.
Throws an exception if it the parameter value isn't a number.request
- current HTTP requestname
- the name of the parameternull
if not presentServletRequestBindingException
- a subclass of ServletException,
so it doesn't need to be caughtpublic static double getDoubleParameter(ServletRequest request, java.lang.String name, double defaultVal)
request
- current HTTP requestname
- the name of the parameterdefaultVal
- the default value to use as fallbackpublic static double[] getDoubleParameters(ServletRequest request, java.lang.String name)
request
- current HTTP requestname
- the name of the parameter with multiple possible valuespublic static double getRequiredDoubleParameter(ServletRequest request, java.lang.String name) throws ServletRequestBindingException
request
- current HTTP requestname
- the name of the parameterServletRequestBindingException
- a subclass of ServletException,
so it doesn't need to be caughtpublic static double[] getRequiredDoubleParameters(ServletRequest request, java.lang.String name) throws ServletRequestBindingException
request
- current HTTP requestname
- the name of the parameter with multiple possible valuesServletRequestBindingException
- a subclass of ServletException,
so it doesn't need to be caughtpublic static java.lang.Boolean getBooleanParameter(ServletRequest request, java.lang.String name) throws ServletRequestBindingException
null
if not present.
Throws an exception if it the parameter value isn't a boolean.
Accepts "true", "on", "yes" (any case) and "1" as values for true; treats every other non-empty value as false (i.e. parses leniently).
request
- current HTTP requestname
- the name of the parameternull
if not presentServletRequestBindingException
- a subclass of ServletException,
so it doesn't need to be caughtpublic static boolean getBooleanParameter(ServletRequest request, java.lang.String name, boolean defaultVal)
Accepts "true", "on", "yes" (any case) and "1" as values for true; treats every other non-empty value as false (i.e. parses leniently).
request
- current HTTP requestname
- the name of the parameterdefaultVal
- the default value to use as fallbackpublic static boolean[] getBooleanParameters(ServletRequest request, java.lang.String name)
Accepts "true", "on", "yes" (any case) and "1" as values for true; treats every other non-empty value as false (i.e. parses leniently).
request
- current HTTP requestname
- the name of the parameter with multiple possible valuespublic static boolean getRequiredBooleanParameter(ServletRequest request, java.lang.String name) throws ServletRequestBindingException
Accepts "true", "on", "yes" (any case) and "1" as values for true; treats every other non-empty value as false (i.e. parses leniently).
request
- current HTTP requestname
- the name of the parameterServletRequestBindingException
- a subclass of ServletException,
so it doesn't need to be caughtpublic static boolean[] getRequiredBooleanParameters(ServletRequest request, java.lang.String name) throws ServletRequestBindingException
Accepts "true", "on", "yes" (any case) and "1" as values for true; treats every other non-empty value as false (i.e. parses leniently).
request
- current HTTP requestname
- the name of the parameterServletRequestBindingException
- a subclass of ServletException,
so it doesn't need to be caughtpublic static java.lang.String getStringParameter(ServletRequest request, java.lang.String name) throws ServletRequestBindingException
null
if not present.request
- current HTTP requestname
- the name of the parameternull
if not presentServletRequestBindingException
- a subclass of ServletException,
so it doesn't need to be caughtpublic static java.lang.String getStringParameter(ServletRequest request, java.lang.String name, java.lang.String defaultVal)
request
- current HTTP requestname
- the name of the parameterdefaultVal
- the default value to use as fallbackpublic static java.lang.String[] getStringParameters(ServletRequest request, java.lang.String name)
request
- current HTTP requestname
- the name of the parameter with multiple possible valuespublic static java.lang.String getRequiredStringParameter(ServletRequest request, java.lang.String name) throws ServletRequestBindingException
request
- current HTTP requestname
- the name of the parameterServletRequestBindingException
- a subclass of ServletException,
so it doesn't need to be caughtpublic static java.lang.String[] getRequiredStringParameters(ServletRequest request, java.lang.String name) throws ServletRequestBindingException
request
- current HTTP requestname
- the name of the parameterServletRequestBindingException
- a subclass of ServletException,
so it doesn't need to be caught