public abstract class

ServletRequestUtils

extends Object
java.lang.Object
   ↳ org.springframework.web.bind.ServletRequestUtils

Class Overview

Parameter extraction methods, for an approach distinct from data binding, in which parameters of specific types are required.

This approach is very useful for simple submissions, where binding request parameters to a command object would be overkill.

Summary

Public Constructors
ServletRequestUtils()
Public Methods
static boolean getBooleanParameter(ServletRequest request, String name, boolean defaultVal)
Get a boolean parameter, with a fallback value.
static Boolean getBooleanParameter(ServletRequest request, String name)
Get a Boolean parameter, or null if not present.
static boolean[] getBooleanParameters(ServletRequest request, String name)
Get an array of boolean parameters, return an empty array if not found.
static double getDoubleParameter(ServletRequest request, String name, double defaultVal)
Get a double parameter, with a fallback value.
static Double getDoubleParameter(ServletRequest request, String name)
Get a Double parameter, or null if not present.
static double[] getDoubleParameters(ServletRequest request, String name)
Get an array of double parameters, return an empty array if not found.
static float getFloatParameter(ServletRequest request, String name, float defaultVal)
Get a float parameter, with a fallback value.
static Float getFloatParameter(ServletRequest request, String name)
Get a Float parameter, or null if not present.
static float[] getFloatParameters(ServletRequest request, String name)
Get an array of float parameters, return an empty array if not found.
static Integer getIntParameter(ServletRequest request, String name)
Get an Integer parameter, or null if not present.
static int getIntParameter(ServletRequest request, String name, int defaultVal)
Get an int parameter, with a fallback value.
static int[] getIntParameters(ServletRequest request, String name)
Get an array of int parameters, return an empty array if not found.
static long getLongParameter(ServletRequest request, String name, long defaultVal)
Get a long parameter, with a fallback value.
static Long getLongParameter(ServletRequest request, String name)
Get a Long parameter, or null if not present.
static long[] getLongParameters(ServletRequest request, String name)
Get an array of long parameters, return an empty array if not found.
static boolean getRequiredBooleanParameter(ServletRequest request, String name)
Get a boolean parameter, throwing an exception if it isn't found or isn't a boolean.
static boolean[] getRequiredBooleanParameters(ServletRequest request, 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, String name)
Get a double parameter, throwing an exception if it isn't found or isn't a number.
static double[] getRequiredDoubleParameters(ServletRequest request, 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, String name)
Get a float parameter, throwing an exception if it isn't found or isn't a number.
static float[] getRequiredFloatParameters(ServletRequest request, 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, String name)
Get an int parameter, throwing an exception if it isn't found or isn't a number.
static int[] getRequiredIntParameters(ServletRequest request, 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, String name)
Get a long parameter, throwing an exception if it isn't found or isn't a number.
static long[] getRequiredLongParameters(ServletRequest request, String name)
Get an array of long parameters, throwing an exception if not found or one is not a number.
static String getRequiredStringParameter(ServletRequest request, String name)
Get a String parameter, throwing an exception if it isn't found.
static String[] getRequiredStringParameters(ServletRequest request, String name)
Get an array of String parameters, throwing an exception if not found.
static String getStringParameter(ServletRequest request, String name, String defaultVal)
Get a String parameter, with a fallback value.
static String getStringParameter(ServletRequest request, String name)
Get a String parameter, or null if not present.
static String[] getStringParameters(ServletRequest request, String name)
Get an array of String parameters, return an empty array if not found.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public ServletRequestUtils ()

Public Methods

public static boolean getBooleanParameter (ServletRequest request, String name, boolean defaultVal)

Get a boolean parameter, with a fallback value. Never throws an exception. Can pass a distinguished value as default to enable checks of whether it was supplied.

Accepts "true", "on", "yes" (any case) and "1" as values for true; treats every other non-empty value as false (i.e. parses leniently).

Parameters
request current HTTP request
name the name of the parameter
defaultVal the default value to use as fallback

public static Boolean getBooleanParameter (ServletRequest request, String name)

Get a Boolean parameter, or 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).

Parameters
request current HTTP request
name the name of the parameter
Returns
  • the Boolean value, or null if not present
Throws
ServletRequestBindingException a subclass of ServletException, so it doesn't need to be caught

public static boolean[] getBooleanParameters (ServletRequest request, String name)

Get an array of boolean parameters, return an empty array if not found.

Accepts "true", "on", "yes" (any case) and "1" as values for true; treats every other non-empty value as false (i.e. parses leniently).

Parameters
request current HTTP request
name the name of the parameter with multiple possible values

public static double getDoubleParameter (ServletRequest request, String name, double defaultVal)

Get a double parameter, with a fallback value. Never throws an exception. Can pass a distinguished value as default to enable checks of whether it was supplied.

Parameters
request current HTTP request
name the name of the parameter
defaultVal the default value to use as fallback

public static Double getDoubleParameter (ServletRequest request, String name)

Get a Double parameter, or null if not present. Throws an exception if it the parameter value isn't a number.

Parameters
request current HTTP request
name the name of the parameter
Returns
  • the Double value, or null if not present
Throws
ServletRequestBindingException a subclass of ServletException, so it doesn't need to be caught

public static double[] getDoubleParameters (ServletRequest request, String name)

Get an array of double parameters, return an empty array if not found.

Parameters
request current HTTP request
name the name of the parameter with multiple possible values

public static float getFloatParameter (ServletRequest request, String name, float defaultVal)

Get a float parameter, with a fallback value. Never throws an exception. Can pass a distinguished value as default to enable checks of whether it was supplied.

Parameters
request current HTTP request
name the name of the parameter
defaultVal the default value to use as fallback

public static Float getFloatParameter (ServletRequest request, String name)

Get a Float parameter, or null if not present. Throws an exception if it the parameter value isn't a number.

Parameters
request current HTTP request
name the name of the parameter
Returns
  • the Float value, or null if not present
Throws
ServletRequestBindingException a subclass of ServletException, so it doesn't need to be caught

public static float[] getFloatParameters (ServletRequest request, String name)

Get an array of float parameters, return an empty array if not found.

Parameters
request current HTTP request
name the name of the parameter with multiple possible values

public static Integer getIntParameter (ServletRequest request, String name)

Get an Integer parameter, or null if not present. Throws an exception if it the parameter value isn't a number.

Parameters
request current HTTP request
name the name of the parameter
Returns
  • the Integer value, or null if not present
Throws
ServletRequestBindingException a subclass of ServletException, so it doesn't need to be caught

public static int getIntParameter (ServletRequest request, String name, int defaultVal)

Get an int parameter, with a fallback value. Never throws an exception. Can pass a distinguished value as default to enable checks of whether it was supplied.

Parameters
request current HTTP request
name the name of the parameter
defaultVal the default value to use as fallback

public static int[] getIntParameters (ServletRequest request, String name)

Get an array of int parameters, return an empty array if not found.

Parameters
request current HTTP request
name the name of the parameter with multiple possible values

public static long getLongParameter (ServletRequest request, String name, long defaultVal)

Get a long parameter, with a fallback value. Never throws an exception. Can pass a distinguished value as default to enable checks of whether it was supplied.

Parameters
request current HTTP request
name the name of the parameter
defaultVal the default value to use as fallback

public static Long getLongParameter (ServletRequest request, String name)

Get a Long parameter, or null if not present. Throws an exception if it the parameter value isn't a number.

Parameters
request current HTTP request
name the name of the parameter
Returns
  • the Long value, or null if not present
Throws
ServletRequestBindingException a subclass of ServletException, so it doesn't need to be caught

public static long[] getLongParameters (ServletRequest request, String name)

Get an array of long parameters, return an empty array if not found.

Parameters
request current HTTP request
name the name of the parameter with multiple possible values

public static boolean getRequiredBooleanParameter (ServletRequest request, String name)

Get a boolean parameter, throwing an exception if it isn't found or 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).

Parameters
request current HTTP request
name the name of the parameter
Throws
ServletRequestBindingException a subclass of ServletException, so it doesn't need to be caught

public static boolean[] getRequiredBooleanParameters (ServletRequest request, String name)

Get an array of boolean parameters, throwing an exception if not found or one 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).

Parameters
request current HTTP request
name the name of the parameter
Throws
ServletRequestBindingException a subclass of ServletException, so it doesn't need to be caught

public static double getRequiredDoubleParameter (ServletRequest request, String name)

Get a double parameter, throwing an exception if it isn't found or isn't a number.

Parameters
request current HTTP request
name the name of the parameter
Throws
ServletRequestBindingException a subclass of ServletException, so it doesn't need to be caught

public static double[] getRequiredDoubleParameters (ServletRequest request, String name)

Get an array of double parameters, throwing an exception if not found or one is not a number.

Parameters
request current HTTP request
name the name of the parameter with multiple possible values
Throws
ServletRequestBindingException a subclass of ServletException, so it doesn't need to be caught

public static float getRequiredFloatParameter (ServletRequest request, String name)

Get a float parameter, throwing an exception if it isn't found or isn't a number.

Parameters
request current HTTP request
name the name of the parameter
Throws
ServletRequestBindingException a subclass of ServletException, so it doesn't need to be caught

public static float[] getRequiredFloatParameters (ServletRequest request, String name)

Get an array of float parameters, throwing an exception if not found or one is not a number.

Parameters
request current HTTP request
name the name of the parameter with multiple possible values
Throws
ServletRequestBindingException a subclass of ServletException, so it doesn't need to be caught

public static int getRequiredIntParameter (ServletRequest request, String name)

Get an int parameter, throwing an exception if it isn't found or isn't a number.

Parameters
request current HTTP request
name the name of the parameter
Throws
ServletRequestBindingException a subclass of ServletException, so it doesn't need to be caught

public static int[] getRequiredIntParameters (ServletRequest request, String name)

Get an array of int parameters, throwing an exception if not found or one is not a number..

Parameters
request current HTTP request
name the name of the parameter with multiple possible values
Throws
ServletRequestBindingException a subclass of ServletException, so it doesn't need to be caught

public static long getRequiredLongParameter (ServletRequest request, String name)

Get a long parameter, throwing an exception if it isn't found or isn't a number.

Parameters
request current HTTP request
name the name of the parameter
Throws
ServletRequestBindingException a subclass of ServletException, so it doesn't need to be caught

public static long[] getRequiredLongParameters (ServletRequest request, String name)

Get an array of long parameters, throwing an exception if not found or one is not a number.

Parameters
request current HTTP request
name the name of the parameter with multiple possible values
Throws
ServletRequestBindingException a subclass of ServletException, so it doesn't need to be caught

public static String getRequiredStringParameter (ServletRequest request, String name)

Get a String parameter, throwing an exception if it isn't found.

Parameters
request current HTTP request
name the name of the parameter
Throws
ServletRequestBindingException a subclass of ServletException, so it doesn't need to be caught

public static String[] getRequiredStringParameters (ServletRequest request, String name)

Get an array of String parameters, throwing an exception if not found.

Parameters
request current HTTP request
name the name of the parameter
Throws
ServletRequestBindingException a subclass of ServletException, so it doesn't need to be caught

public static String getStringParameter (ServletRequest request, String name, String defaultVal)

Get a String parameter, with a fallback value. Never throws an exception. Can pass a distinguished value to default to enable checks of whether it was supplied.

Parameters
request current HTTP request
name the name of the parameter
defaultVal the default value to use as fallback

public static String getStringParameter (ServletRequest request, String name)

Get a String parameter, or null if not present.

Parameters
request current HTTP request
name the name of the parameter
Returns
  • the String value, or null if not present
Throws
ServletRequestBindingException a subclass of ServletException, so it doesn't need to be caught

public static String[] getStringParameters (ServletRequest request, String name)

Get an array of String parameters, return an empty array if not found.

Parameters
request current HTTP request
name the name of the parameter with multiple possible values