类 ServletRequestUtils


  • public abstract class ServletRequestUtils
    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.

    从以下版本开始:
    2.0
    作者:
    Juergen Hoeller, Keith Donald
    • 方法详细资料

      • getIntParameter

        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.
        参数:
        request - current HTTP request
        name - the name of the parameter
        defaultVal - the default value to use as fallback
      • getIntParameters

        public static int[] getIntParameters​(ServletRequest request,
                                             String name)
        Get an array of int parameters, return an empty array if not found.
        参数:
        request - current HTTP request
        name - the name of the parameter with multiple possible values
      • getLongParameter

        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.
        参数:
        request - current HTTP request
        name - the name of the parameter
        defaultVal - the default value to use as fallback
      • getLongParameters

        public static long[] getLongParameters​(ServletRequest request,
                                               String name)
        Get an array of long parameters, return an empty array if not found.
        参数:
        request - current HTTP request
        name - the name of the parameter with multiple possible values
      • getFloatParameter

        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.
        参数:
        request - current HTTP request
        name - the name of the parameter
        defaultVal - the default value to use as fallback
      • getFloatParameters

        public static float[] getFloatParameters​(ServletRequest request,
                                                 String name)
        Get an array of float parameters, return an empty array if not found.
        参数:
        request - current HTTP request
        name - the name of the parameter with multiple possible values
      • getDoubleParameter

        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.
        参数:
        request - current HTTP request
        name - the name of the parameter
        defaultVal - the default value to use as fallback
      • getDoubleParameters

        public static double[] getDoubleParameters​(ServletRequest request,
                                                   String name)
        Get an array of double parameters, return an empty array if not found.
        参数:
        request - current HTTP request
        name - the name of the parameter with multiple possible values
      • getBooleanParameter

        public static Boolean getBooleanParameter​(ServletRequest request,
                                                  String name)
                                           throws ServletRequestBindingException
        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).

        参数:
        request - current HTTP request
        name - the name of the parameter
        返回:
        the Boolean value, or null if not present
        抛出:
        ServletRequestBindingException - a subclass of ServletException, so it doesn't need to be caught
      • getBooleanParameter

        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).

        参数:
        request - current HTTP request
        name - the name of the parameter
        defaultVal - the default value to use as fallback
      • getBooleanParameters

        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).

        参数:
        request - current HTTP request
        name - the name of the parameter with multiple possible values
      • getRequiredBooleanParameter

        public 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).

        参数:
        request - current HTTP request
        name - the name of the parameter
        抛出:
        ServletRequestBindingException - a subclass of ServletException, so it doesn't need to be caught
      • getRequiredBooleanParameters

        public 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).

        参数:
        request - current HTTP request
        name - the name of the parameter
        抛出:
        ServletRequestBindingException - a subclass of ServletException, so it doesn't need to be caught
      • getStringParameter

        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.
        参数:
        request - current HTTP request
        name - the name of the parameter
        defaultVal - the default value to use as fallback
      • getStringParameters

        public static String[] getStringParameters​(ServletRequest request,
                                                   String name)
        Get an array of String parameters, return an empty array if not found.
        参数:
        request - current HTTP request
        name - the name of the parameter with multiple possible values