Class ServletRequestUtils
This approach is very useful for simple submissions, where binding request parameters to a command object would be overkill.
- Since:
- 2.0
- Author:
- Juergen Hoeller, Keith Donald
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetBooleanParameter(jakarta.servlet.ServletRequest request, String name) Get a Boolean parameter, ornullif not present.static booleangetBooleanParameter(jakarta.servlet.ServletRequest request, String name, boolean defaultVal) Get a boolean parameter, with a fallback value.static boolean[]getBooleanParameters(jakarta.servlet.ServletRequest request, String name) Get an array of boolean parameters, return an empty array if not found.getDoubleParameter(jakarta.servlet.ServletRequest request, String name) Get a Double parameter, ornullif not present.static doublegetDoubleParameter(jakarta.servlet.ServletRequest request, String name, double defaultVal) Get a double parameter, with a fallback value.static double[]getDoubleParameters(jakarta.servlet.ServletRequest request, String name) Get an array of double parameters, return an empty array if not found.getFloatParameter(jakarta.servlet.ServletRequest request, String name) Get a Float parameter, ornullif not present.static floatgetFloatParameter(jakarta.servlet.ServletRequest request, String name, float defaultVal) Get a float parameter, with a fallback value.static float[]getFloatParameters(jakarta.servlet.ServletRequest request, String name) Get an array of float parameters, return an empty array if not found.getIntParameter(jakarta.servlet.ServletRequest request, String name) Get an Integer parameter, ornullif not present.static intgetIntParameter(jakarta.servlet.ServletRequest request, String name, int defaultVal) Get an int parameter, with a fallback value.static int[]getIntParameters(jakarta.servlet.ServletRequest request, String name) Get an array of int parameters, return an empty array if not found.getLongParameter(jakarta.servlet.ServletRequest request, String name) Get a Long parameter, ornullif not present.static longgetLongParameter(jakarta.servlet.ServletRequest request, String name, long defaultVal) Get a long parameter, with a fallback value.static long[]getLongParameters(jakarta.servlet.ServletRequest request, String name) Get an array of long parameters, return an empty array if not found.static booleangetRequiredBooleanParameter(jakarta.servlet.ServletRequest request, String name) Get a boolean parameter, throwing an exception if it isn't found or isn't a boolean.static boolean[]getRequiredBooleanParameters(jakarta.servlet.ServletRequest request, String name) Get an array of boolean parameters, throwing an exception if not found or one isn't a boolean.static doublegetRequiredDoubleParameter(jakarta.servlet.ServletRequest request, String name) Get a double parameter, throwing an exception if it isn't found or isn't a number.static double[]getRequiredDoubleParameters(jakarta.servlet.ServletRequest request, String name) Get an array of double parameters, throwing an exception if not found or one is not a number.static floatgetRequiredFloatParameter(jakarta.servlet.ServletRequest request, String name) Get a float parameter, throwing an exception if it isn't found or isn't a number.static float[]getRequiredFloatParameters(jakarta.servlet.ServletRequest request, String name) Get an array of float parameters, throwing an exception if not found or one is not a number.static intgetRequiredIntParameter(jakarta.servlet.ServletRequest request, String name) Get an int parameter, throwing an exception if it isn't found or isn't a number.static int[]getRequiredIntParameters(jakarta.servlet.ServletRequest request, String name) Get an array of int parameters, throwing an exception if not found or one is not a number.static longgetRequiredLongParameter(jakarta.servlet.ServletRequest request, String name) Get a long parameter, throwing an exception if it isn't found or isn't a number.static long[]getRequiredLongParameters(jakarta.servlet.ServletRequest request, String name) Get an array of long parameters, throwing an exception if not found or one is not a number.static StringgetRequiredStringParameter(jakarta.servlet.ServletRequest request, String name) Get a String parameter, throwing an exception if it isn't found.static String[]getRequiredStringParameters(jakarta.servlet.ServletRequest request, String name) Get an array of String parameters, throwing an exception if not found.getStringParameter(jakarta.servlet.ServletRequest request, String name) Get a String parameter, ornullif not present.static StringgetStringParameter(jakarta.servlet.ServletRequest request, String name, String defaultVal) Get a String parameter, with a fallback value.static String[]getStringParameters(jakarta.servlet.ServletRequest request, String name) Get an array of String parameters, return an empty array if not found.
-
Constructor Details
-
ServletRequestUtils
public ServletRequestUtils()
-
-
Method Details
-
getIntParameter
public static @Nullable Integer getIntParameter(jakarta.servlet.ServletRequest request, String name) throws ServletRequestBindingException Get an Integer parameter, ornullif not present. Throws an exception if the parameter value isn't a number.- Parameters:
request- current HTTP requestname- the name of the parameter- Returns:
- the Integer value, or
nullif not present - Throws:
ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
-
getIntParameter
public static int getIntParameter(jakarta.servlet.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 requestname- the name of the parameterdefaultVal- the default value to use as fallback
-
getIntParameters
Get an array of int parameters, return an empty array if not found.- Parameters:
request- current HTTP requestname- the name of the parameter with multiple possible values
-
getRequiredIntParameter
public static int getRequiredIntParameter(jakarta.servlet.ServletRequest request, String name) throws ServletRequestBindingException Get an int parameter, throwing an exception if it isn't found or isn't a number.- Parameters:
request- current HTTP requestname- the name of the parameter- Throws:
ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
-
getRequiredIntParameters
public static int[] getRequiredIntParameters(jakarta.servlet.ServletRequest request, String name) throws ServletRequestBindingException Get an array of int parameters, throwing an exception if not found or one is not a number.- Parameters:
request- current HTTP requestname- the name of the parameter with multiple possible values- Throws:
ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
-
getLongParameter
public static @Nullable Long getLongParameter(jakarta.servlet.ServletRequest request, String name) throws ServletRequestBindingException Get a Long parameter, ornullif not present. Throws an exception if the parameter value isn't a number.- Parameters:
request- current HTTP requestname- the name of the parameter- Returns:
- the Long value, or
nullif not present - Throws:
ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
-
getLongParameter
public static long getLongParameter(jakarta.servlet.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 requestname- the name of the parameterdefaultVal- the default value to use as fallback
-
getLongParameters
Get an array of long parameters, return an empty array if not found.- Parameters:
request- current HTTP requestname- the name of the parameter with multiple possible values
-
getRequiredLongParameter
public static long getRequiredLongParameter(jakarta.servlet.ServletRequest request, String name) throws ServletRequestBindingException Get a long parameter, throwing an exception if it isn't found or isn't a number.- Parameters:
request- current HTTP requestname- the name of the parameter- Throws:
ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
-
getRequiredLongParameters
public static long[] getRequiredLongParameters(jakarta.servlet.ServletRequest request, String name) throws ServletRequestBindingException Get an array of long parameters, throwing an exception if not found or one is not a number.- Parameters:
request- current HTTP requestname- the name of the parameter with multiple possible values- Throws:
ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
-
getFloatParameter
public static @Nullable Float getFloatParameter(jakarta.servlet.ServletRequest request, String name) throws ServletRequestBindingException Get a Float parameter, ornullif not present. Throws an exception if the parameter value isn't a number.- Parameters:
request- current HTTP requestname- the name of the parameter- Returns:
- the Float value, or
nullif not present - Throws:
ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
-
getFloatParameter
public static float getFloatParameter(jakarta.servlet.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 requestname- the name of the parameterdefaultVal- the default value to use as fallback
-
getFloatParameters
Get an array of float parameters, return an empty array if not found.- Parameters:
request- current HTTP requestname- the name of the parameter with multiple possible values
-
getRequiredFloatParameter
public static float getRequiredFloatParameter(jakarta.servlet.ServletRequest request, String name) throws ServletRequestBindingException Get a float parameter, throwing an exception if it isn't found or isn't a number.- Parameters:
request- current HTTP requestname- the name of the parameter- Throws:
ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
-
getRequiredFloatParameters
public static float[] getRequiredFloatParameters(jakarta.servlet.ServletRequest request, String name) throws ServletRequestBindingException Get an array of float parameters, throwing an exception if not found or one is not a number.- Parameters:
request- current HTTP requestname- the name of the parameter with multiple possible values- Throws:
ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
-
getDoubleParameter
public static @Nullable Double getDoubleParameter(jakarta.servlet.ServletRequest request, String name) throws ServletRequestBindingException Get a Double parameter, ornullif not present. Throws an exception if the parameter value isn't a number.- Parameters:
request- current HTTP requestname- the name of the parameter- Returns:
- the Double value, or
nullif not present - Throws:
ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
-
getDoubleParameter
public static double getDoubleParameter(jakarta.servlet.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 requestname- the name of the parameterdefaultVal- the default value to use as fallback
-
getDoubleParameters
Get an array of double parameters, return an empty array if not found.- Parameters:
request- current HTTP requestname- the name of the parameter with multiple possible values
-
getRequiredDoubleParameter
public static double getRequiredDoubleParameter(jakarta.servlet.ServletRequest request, String name) throws ServletRequestBindingException Get a double parameter, throwing an exception if it isn't found or isn't a number.- Parameters:
request- current HTTP requestname- the name of the parameter- Throws:
ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
-
getRequiredDoubleParameters
public static double[] getRequiredDoubleParameters(jakarta.servlet.ServletRequest request, String name) throws ServletRequestBindingException Get an array of double parameters, throwing an exception if not found or one is not a number.- Parameters:
request- current HTTP requestname- the name of the parameter with multiple possible values- Throws:
ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
-
getBooleanParameter
public static @Nullable Boolean getBooleanParameter(jakarta.servlet.ServletRequest request, String name) throws ServletRequestBindingException Get a Boolean parameter, ornullif not present. Throws an exception if 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 requestname- the name of the parameter- Returns:
- the Boolean value, or
nullif not present - Throws:
ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
-
getBooleanParameter
public static boolean getBooleanParameter(jakarta.servlet.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 requestname- the name of the parameterdefaultVal- the default value to use as fallback
-
getBooleanParameters
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 requestname- the name of the parameter with multiple possible values
-
getRequiredBooleanParameter
public static boolean getRequiredBooleanParameter(jakarta.servlet.ServletRequest request, String name) throws ServletRequestBindingException 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 requestname- the name of the parameter- Throws:
ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
-
getRequiredBooleanParameters
public static boolean[] getRequiredBooleanParameters(jakarta.servlet.ServletRequest request, String name) throws ServletRequestBindingException 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 requestname- the name of the parameter- Throws:
ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
-
getStringParameter
public static @Nullable String getStringParameter(jakarta.servlet.ServletRequest request, String name) throws ServletRequestBindingException Get a String parameter, ornullif not present.- Parameters:
request- current HTTP requestname- the name of the parameter- Returns:
- the String value, or
nullif not present - Throws:
ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
-
getStringParameter
public static String getStringParameter(jakarta.servlet.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 requestname- the name of the parameterdefaultVal- the default value to use as fallback
-
getStringParameters
-
getRequiredStringParameter
public static String getRequiredStringParameter(jakarta.servlet.ServletRequest request, String name) throws ServletRequestBindingException Get a String parameter, throwing an exception if it isn't found.- Parameters:
request- current HTTP requestname- the name of the parameter- Throws:
ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
-
getRequiredStringParameters
public static String[] getRequiredStringParameters(jakarta.servlet.ServletRequest request, String name) throws ServletRequestBindingException Get an array of String parameters, throwing an exception if not found.- Parameters:
request- current HTTP requestname- the name of the parameter- Throws:
ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
-