Class HiddenHttpMethodFilter

  extended by org.springframework.web.filter.GenericFilterBean
      extended by org.springframework.web.filter.OncePerRequestFilter
          extended by org.springframework.web.filter.HiddenHttpMethodFilter
All Implemented Interfaces:
Aware, BeanNameAware, DisposableBean, InitializingBean, EnvironmentAware, ServletContextAware

public class HiddenHttpMethodFilter
extends OncePerRequestFilter

javax.servlet.Filter that converts posted method parameters into HTTP methods, retrievable via HttpServletRequest#getMethod(). Since browsers currently only support GET and POST, a common technique - used by the Prototype library, for instance - is to use a normal POST with an additional hidden form field (_method) to pass the "real" HTTP method along. This filter reads that parameter and changes the HttpServletRequestWrapper#getMethod() return value accordingly.

The name of the request parameter defaults to _method, but can be adapted via the methodParam property.

NOTE: This filter needs to run after multipart processing in case of a multipart POST request, due to its inherent need for checking a POST body parameter. So typically, put a Spring MultipartFilter before this HiddenHttpMethodFilter in your web.xml filter chain.

Arjen Poutsma

Nested Class Summary
private static class HiddenHttpMethodFilter.HttpMethodRequestWrapper
          Simple HttpServletRequest wrapper that returns the supplied method for HttpServletRequest#getMethod().
Field Summary
static java.lang.String DEFAULT_METHOD_PARAM
          Default method parameter: _method
private  java.lang.String methodParam
Fields inherited from class org.springframework.web.filter.OncePerRequestFilter
Fields inherited from class org.springframework.web.filter.GenericFilterBean
Constructor Summary
Method Summary
protected  void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
          Same contract as for doFilter, but guaranteed to be just invoked once per request.
 void setMethodParam(java.lang.String methodParam)
          Set the parameter name to look for HTTP methods.
Methods inherited from class org.springframework.web.filter.OncePerRequestFilter
doFilter, getAlreadyFilteredAttributeName, shouldNotFilter
Methods inherited from class org.springframework.web.filter.GenericFilterBean
addRequiredProperty, afterPropertiesSet, destroy, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


public static final java.lang.String DEFAULT_METHOD_PARAM
Default method parameter: _method

See Also:
Constant Field Values


private java.lang.String methodParam
Constructor Detail


public HiddenHttpMethodFilter()
Method Detail


public void setMethodParam(java.lang.String methodParam)
Set the parameter name to look for HTTP methods.

See Also:


protected void doFilterInternal(HttpServletRequest request,
                                HttpServletResponse response,
                                FilterChain filterChain)
                         throws ServletException,
Description copied from class: OncePerRequestFilter
Same contract as for doFilter, but guaranteed to be just invoked once per request. Provides HttpServletRequest and HttpServletResponse arguments instead of the default ServletRequest and ServletResponse ones.

Specified by:
doFilterInternal in class OncePerRequestFilter