public class HiddenHttpMethodFilter
extends org.springframework.web.filter.OncePerRequestFilter
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.
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_METHOD_PARAM
Default method parameter:
_method |
Constructor and Description |
---|
HiddenHttpMethodFilter() |
Modifier and Type | Method and Description |
---|---|
protected void |
doFilterInternal(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
javax.servlet.FilterChain filterChain) |
void |
setMethodParam(String methodParam)
Set the parameter name to look for HTTP methods.
|
doFilter, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterAsyncDispatch, shouldNotFilterErrorDispatch
public static final String DEFAULT_METHOD_PARAM
_method
public void setMethodParam(String methodParam)
DEFAULT_METHOD_PARAM
protected void doFilterInternal(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain filterChain) throws javax.servlet.ServletException, IOException
doFilterInternal
in class org.springframework.web.filter.OncePerRequestFilter
javax.servlet.ServletException
IOException
Copyright © 2006–2018 TinyGroup. All rights reserved.