org.springframework.web.bind
Class RequestUtils

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

public abstract class RequestUtils
extends java.lang.Object

Parameter extraction methods, for an approach distinct from data binding, in which parameters of specific types are required. This is very useful for simple submissions.

Author:
Rod Johnson, Juergen Hoeller, Jean-Pierre Pawlak

Constructor Summary
RequestUtils()
           
 
Method Summary
static boolean getBooleanParameter(javax.servlet.http.HttpServletRequest request, java.lang.String name, boolean defaultVal)
          Get a boolean parameter, with a fallback value.
static double getDoubleParameter(javax.servlet.http.HttpServletRequest request, java.lang.String name, double defaultVal)
          Get a double parameter, with a fallback value.
static float getFloatParameter(javax.servlet.http.HttpServletRequest request, java.lang.String name, float defaultVal)
          Get a double parameter, with a fallback value.
static int getIntParameter(javax.servlet.http.HttpServletRequest request, java.lang.String name, int defaultVal)
          Get an int parameter, with a fallback value.
static long getLongParameter(javax.servlet.http.HttpServletRequest request, java.lang.String name, long defaultVal)
          Get an int parameter, with a fallback value.
static boolean getRequiredBooleanParameter(javax.servlet.http.HttpServletRequest request, java.lang.String name)
          Get a boolean parameter, throwing an exception if it isn't found or isn't a boolean.
static double getRequiredDoubleParameter(javax.servlet.http.HttpServletRequest request, java.lang.String name)
          Get a double parameter, throwing an exception if it isn't found or isn't a number.
static float getRequiredFloatParameter(javax.servlet.http.HttpServletRequest request, java.lang.String name)
          Get a double parameter, throwing an exception if it isn't found or isn't a number.
static int getRequiredIntParameter(javax.servlet.http.HttpServletRequest request, java.lang.String name)
          Get an int parameter, throwing an exception if it isn't found or isn't a number.
static long getRequiredLongParameter(javax.servlet.http.HttpServletRequest request, java.lang.String name)
          Get a long parameter, throwing an exception if it isn't found or isn't a number.
static java.lang.String getRequiredStringParameter(javax.servlet.http.HttpServletRequest request, java.lang.String name)
          Get a string parameter, throwing an exception if it isn't found or is empty.
static java.lang.String getStringParameter(javax.servlet.http.HttpServletRequest request, java.lang.String name, java.lang.String defaultVal)
          Get a string parameter, with a fallback value.
static void rejectRequestMethod(javax.servlet.http.HttpServletRequest request, java.lang.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(javax.servlet.http.HttpServletRequest request,
                                       java.lang.String method)
                                throws javax.servlet.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:
javax.servlet.ServletException - if the given HTTP request is rejected

getIntParameter

public static int getIntParameter(javax.servlet.http.HttpServletRequest request,
                                  java.lang.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.


getRequiredIntParameter

public static int getRequiredIntParameter(javax.servlet.http.HttpServletRequest request,
                                          java.lang.String name)
                                   throws ServletRequestBindingException
Get an int parameter, throwing an exception if it isn't found or isn't a number.

Throws:
ServletRequestBindingException: - subclass of ServletException, so it doesn't need to be caught
ServletRequestBindingException

getLongParameter

public static long getLongParameter(javax.servlet.http.HttpServletRequest request,
                                    java.lang.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.


getRequiredLongParameter

public static long getRequiredLongParameter(javax.servlet.http.HttpServletRequest request,
                                            java.lang.String name)
                                     throws ServletRequestBindingException
Get a long parameter, throwing an exception if it isn't found or isn't a number.

Throws:
ServletRequestBindingException: - subclass of ServletException, so it doesn't need to be caught
ServletRequestBindingException

getFloatParameter

public static float getFloatParameter(javax.servlet.http.HttpServletRequest request,
                                      java.lang.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.


getRequiredFloatParameter

public static float getRequiredFloatParameter(javax.servlet.http.HttpServletRequest request,
                                              java.lang.String name)
                                       throws ServletRequestBindingException
Get a double parameter, throwing an exception if it isn't found or isn't a number.

Throws:
ServletRequestBindingException: - subclass of ServletException, so it doesn't need to be caught
ServletRequestBindingException

getDoubleParameter

public static double getDoubleParameter(javax.servlet.http.HttpServletRequest request,
                                        java.lang.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.


getRequiredDoubleParameter

public static double getRequiredDoubleParameter(javax.servlet.http.HttpServletRequest request,
                                                java.lang.String name)
                                         throws ServletRequestBindingException
Get a double parameter, throwing an exception if it isn't found or isn't a number.

Throws:
ServletRequestBindingException: - subclass of ServletException, so it doesn't need to be caught
ServletRequestBindingException

getBooleanParameter

public static boolean getBooleanParameter(javax.servlet.http.HttpServletRequest request,
                                          java.lang.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.


getRequiredBooleanParameter

public static boolean getRequiredBooleanParameter(javax.servlet.http.HttpServletRequest request,
                                                  java.lang.String name)
                                           throws ServletRequestBindingException
Get a boolean parameter, 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".

Throws:
ServletRequestBindingException: - subclass of ServletException, so it doesn't need to be caught
ServletRequestBindingException

getStringParameter

public static java.lang.String getStringParameter(javax.servlet.http.HttpServletRequest request,
                                                  java.lang.String name,
                                                  java.lang.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.


getRequiredStringParameter

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

Throws:
ServletRequestBindingException: - subclass of ServletException, so it doesn't need to be caught
ServletRequestBindingException


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