org.springframework.web.bind
Class RequestUtils

java.lang.Object
  extended byorg.springframework.web.bind.RequestUtils

public abstract class RequestUtils
extends Object

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.

Author:
Rod Johnson, Juergen Hoeller, Keith Donald

Constructor Summary
RequestUtils()
           
 
Method Summary
static boolean getBooleanParameter(HttpServletRequest request, String name, boolean defaultVal)
          Get a boolean parameter, with a fallback value.
static boolean[] getBooleanParameters(HttpServletRequest request, String name)
          Get an array of boolean parameters, return an empty array if not found.
static double getDoubleParameter(HttpServletRequest request, String name, double defaultVal)
          Get a double parameter, with a fallback value.
static double[] getDoubleParameters(HttpServletRequest request, String name)
          Get an array of float parameters, return an empty array if not found.
static float getFloatParameter(HttpServletRequest request, String name, float defaultVal)
          Get a double parameter, with a fallback value.
static float[] getFloatParameters(HttpServletRequest request, String name)
          Get an array of float parameters, return an empty array if not found.
static int getIntParameter(HttpServletRequest request, String name, int defaultVal)
          Get an int parameter, with a fallback value.
static int[] getIntParameters(HttpServletRequest request, String name)
          Get an array of int parameters, return an empty array if not found.
static long getLongParameter(HttpServletRequest request, String name, long defaultVal)
          Get an int parameter, with a fallback value.
static long[] getLongParameters(HttpServletRequest request, String name)
          Get an array of long parameters, return an empty array if not found.
static boolean getRequiredBooleanParameter(HttpServletRequest request, String name)
          Get an array of boolean parameters, throwing an exception if it isn't found or isn't a boolean.
static boolean[] getRequiredBooleanParameters(HttpServletRequest request, String name)
          Get an array of boolean parameters, throwing an exception if not found or one isn't a boolean.
static double getRequiredDoubleParameter(HttpServletRequest request, String name)
          Get a double parameter, throwing an exception if it isn't found or isn't a number.
static double[] getRequiredDoubleParameters(HttpServletRequest request, String name)
          Get an array of double parameters, throwing an exception if not found or one is not a number.
static float getRequiredFloatParameter(HttpServletRequest request, String name)
          Get a double parameter, throwing an exception if it isn't found or isn't a number.
static float[] getRequiredFloatParameters(HttpServletRequest request, String name)
          Get an array of float parameters, throwing an exception if not found or one is not a number.
static int getRequiredIntParameter(HttpServletRequest request, String name)
          Get an int parameter, throwing an exception if it isn't found or isn't a number.
static int[] getRequiredIntParameters(HttpServletRequest request, String name)
          Get an array of int parameters, throwing an exception if not found or one is not a number..
static long getRequiredLongParameter(HttpServletRequest request, String name)
          Get a long parameter, throwing an exception if it isn't found or isn't a number.
static long[] getRequiredLongParameters(HttpServletRequest request, String name)
          Get an array of long parameters, throwing an exception if not found or one is not a number.
static String getRequiredStringParameter(HttpServletRequest request, String name)
          Get a string parameter, throwing an exception if it isn't found or is empty.
static String[] getRequiredStringParameters(HttpServletRequest request, String name)
          Get an array of string parameters, throwing an exception if not found or one is empty.
static String getStringParameter(HttpServletRequest request, String name, String defaultVal)
          Get a string parameter, with a fallback value.
static String[] getStringParameters(HttpServletRequest request, String name)
          Get an array of String parameters, return an empty array if not found.
static void rejectRequestMethod(HttpServletRequest request, String method)
          Throw a ServletException if the given HTTP request method should be rejected.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestUtils

public RequestUtils()
Method Detail

rejectRequestMethod

public static void rejectRequestMethod(HttpServletRequest request,
                                       String method)
                                throws ServletException
Throw a ServletException if the given HTTP request method should be rejected.

Parameters:
request - request to check
method - method (such as "GET") which should be rejected
Throws:
ServletException - if the given HTTP request is rejected

getIntParameter

public static int getIntParameter(HttpServletRequest 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

getIntParameters

public static int[] getIntParameters(HttpServletRequest 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

getRequiredIntParameter

public static int getRequiredIntParameter(HttpServletRequest 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: - subclass of ServletException, so it doesn't need to be caught
ServletRequestBindingException

getRequiredIntParameters

public static int[] getRequiredIntParameters(HttpServletRequest 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: - subclass of ServletException, so it doesn't need to be caught
ServletRequestBindingException

getLongParameter

public static long getLongParameter(HttpServletRequest request,
                                    String name,
                                    long 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

getLongParameters

public static long[] getLongParameters(HttpServletRequest 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

getRequiredLongParameter

public static long getRequiredLongParameter(HttpServletRequest 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: - subclass of ServletException, so it doesn't need to be caught
ServletRequestBindingException

getRequiredLongParameters

public static long[] getRequiredLongParameters(HttpServletRequest 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: - subclass of ServletException, so it doesn't need to be caught
ServletRequestBindingException

getFloatParameter

public static float getFloatParameter(HttpServletRequest request,
                                      String name,
                                      float 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

getFloatParameters

public static float[] getFloatParameters(HttpServletRequest 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

getRequiredFloatParameter

public static float getRequiredFloatParameter(HttpServletRequest 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: - subclass of ServletException, so it doesn't need to be caught
ServletRequestBindingException

getRequiredFloatParameters

public static float[] getRequiredFloatParameters(HttpServletRequest 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: - subclass of ServletException, so it doesn't need to be caught
ServletRequestBindingException

getDoubleParameter

public static double getDoubleParameter(HttpServletRequest 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

getDoubleParameters

public static double[] getDoubleParameters(HttpServletRequest 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

getRequiredDoubleParameter

public static double getRequiredDoubleParameter(HttpServletRequest 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: - subclass of ServletException, so it doesn't need to be caught
ServletRequestBindingException

getRequiredDoubleParameters

public static double[] getRequiredDoubleParameters(HttpServletRequest 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: - subclass of ServletException, so it doesn't need to be caught
ServletRequestBindingException

getBooleanParameter

public static boolean getBooleanParameter(HttpServletRequest 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.

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

getBooleanParameters

public static boolean[] getBooleanParameters(HttpServletRequest request,
                                             String name)
Get an array of boolean parameters, return an empty array if not found.

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

getRequiredBooleanParameter

public static boolean getRequiredBooleanParameter(HttpServletRequest request,
                                                  String name)
                                           throws ServletRequestBindingException
Get an array of boolean parameters, throwing an exception if it isn't found or isn't a boolean. True is "true" or "yes" or "on" (ignoring the case) or "1".

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

getRequiredBooleanParameters

public static boolean[] getRequiredBooleanParameters(HttpServletRequest request,
                                                     String name)
                                              throws ServletRequestBindingException
Get an array of boolean parameters, throwing an exception if not found or one isn't a boolean. True is "true" or "yes" or "on" (ignoring the case) or "1".

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

getStringParameter

public static String getStringParameter(HttpServletRequest 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

getStringParameters

public static String[] getStringParameters(HttpServletRequest 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

getRequiredStringParameter

public static String getRequiredStringParameter(HttpServletRequest request,
                                                String name)
                                         throws ServletRequestBindingException
Get a string parameter, throwing an exception if it isn't found or is empty.

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

getRequiredStringParameters

public static String[] getRequiredStringParameters(HttpServletRequest request,
                                                   String name)
                                            throws ServletRequestBindingException
Get an array of string parameters, throwing an exception if not found or one is empty.

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


Copyright (C) 2003-2004 The Spring Framework Project.