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 SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic BooleangetBooleanParameter(ServletRequest request, String name) Get a Boolean parameter, ornullif not present.static booleangetBooleanParameter(ServletRequest request, String name, boolean defaultVal) Get a boolean parameter, with a fallback value.static boolean[]getBooleanParameters(ServletRequest request, String name) Get an array of boolean parameters, return an empty array if not found.static DoublegetDoubleParameter(ServletRequest request, String name) Get a Double parameter, ornullif not present.static doublegetDoubleParameter(ServletRequest request, String name, double defaultVal) Get a double parameter, with a fallback value.static double[]getDoubleParameters(ServletRequest request, String name) Get an array of double parameters, return an empty array if not found.static FloatgetFloatParameter(ServletRequest request, String name) Get a Float parameter, ornullif not present.static floatgetFloatParameter(ServletRequest request, String name, float defaultVal) Get a float parameter, with a fallback value.static float[]getFloatParameters(ServletRequest request, String name) Get an array of float parameters, return an empty array if not found.static IntegergetIntParameter(ServletRequest request, String name) Get an Integer parameter, ornullif not present.static intgetIntParameter(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 LonggetLongParameter(ServletRequest request, String name) Get a Long parameter, ornullif not present.static longgetLongParameter(ServletRequest request, String name, long defaultVal) Get a long parameter, with a fallback value.static long[]getLongParameters(ServletRequest request, String name) Get an array of long parameters, return an empty array if not found.static booleangetRequiredBooleanParameter(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 doublegetRequiredDoubleParameter(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 floatgetRequiredFloatParameter(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 intgetRequiredIntParameter(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 longgetRequiredLongParameter(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 StringgetRequiredStringParameter(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 StringgetStringParameter(ServletRequest request, String name) Get a String parameter, ornullif not present.static StringgetStringParameter(ServletRequest request, String name, String defaultVal) Get a String parameter, with a fallback value.static String[]getStringParameters(ServletRequest request, String name) Get an array of String parameters, return an empty array if not found.
- 
Constructor Details- 
ServletRequestUtilspublic ServletRequestUtils()
 
- 
- 
Method Details- 
getIntParameter@Nullable public static Integer getIntParameter(ServletRequest request, String name) throws ServletRequestBindingException Get an Integer parameter, ornullif 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 nullif not present
- Throws:
- ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
 
- 
getIntParameterGet 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
 
- 
getIntParametersGet 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
 
- 
getRequiredIntParameterpublic static int getRequiredIntParameter(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 request
- name- the name of the parameter
- Throws:
- ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
 
- 
getRequiredIntParameterspublic static int[] getRequiredIntParameters(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 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
 
- 
getLongParameter@Nullable public static Long getLongParameter(ServletRequest request, String name) throws ServletRequestBindingException Get a Long parameter, ornullif 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 nullif not present
- Throws:
- ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
 
- 
getLongParameterGet 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
 
- 
getLongParametersGet 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
 
- 
getRequiredLongParameterpublic static long getRequiredLongParameter(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 request
- name- the name of the parameter
- Throws:
- ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
 
- 
getRequiredLongParameterspublic static long[] getRequiredLongParameters(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 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
 
- 
getFloatParameter@Nullable public static Float getFloatParameter(ServletRequest request, String name) throws ServletRequestBindingException Get a Float parameter, ornullif 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 nullif not present
- Throws:
- ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
 
- 
getFloatParameterGet 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
 
- 
getFloatParametersGet 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
 
- 
getRequiredFloatParameterpublic static float getRequiredFloatParameter(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 request
- name- the name of the parameter
- Throws:
- ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
 
- 
getRequiredFloatParameterspublic static float[] getRequiredFloatParameters(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 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
 
- 
getDoubleParameter@Nullable public static Double getDoubleParameter(ServletRequest request, String name) throws ServletRequestBindingException Get a Double parameter, ornullif 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 nullif not present
- Throws:
- ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
 
- 
getDoubleParameterGet 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
 
- 
getDoubleParametersGet 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
 
- 
getRequiredDoubleParameterpublic static double getRequiredDoubleParameter(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 request
- name- the name of the parameter
- Throws:
- ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
 
- 
getRequiredDoubleParameterspublic static double[] getRequiredDoubleParameters(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 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
 
- 
getBooleanParameter@Nullable public static Boolean getBooleanParameter(ServletRequest request, String name) throws ServletRequestBindingException Get a Boolean parameter, ornullif 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 nullif not present
- Throws:
- ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
 
- 
getBooleanParameterGet 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
 
- 
getBooleanParametersGet 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
 
- 
getRequiredBooleanParameterpublic static boolean getRequiredBooleanParameter(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 request
- name- the name of the parameter
- Throws:
- ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
 
- 
getRequiredBooleanParameterspublic static boolean[] getRequiredBooleanParameters(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 request
- name- the name of the parameter
- Throws:
- ServletRequestBindingException- a subclass of ServletException, so it doesn't need to be caught
 
- 
getStringParameter@Nullable public static String getStringParameter(ServletRequest request, String name) throws ServletRequestBindingException Get a String parameter, ornullif not present.- Parameters:
- request- current HTTP request
- name- 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
 
- 
getStringParameterGet 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
 
- 
getStringParametersGet 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
 
- 
getRequiredStringParameterpublic static String getRequiredStringParameter(ServletRequest request, String name) throws ServletRequestBindingException 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
 
- 
getRequiredStringParameterspublic static String[] getRequiredStringParameters(ServletRequest request, String name) throws ServletRequestBindingException 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
 
 
-