Using the @RequestMapping
annotation, it is straightforward to define REST APIs
using a richer set of HTTP methods to specify the semantics of each operation, for example
GET, POST, PUT, and DELETE.
To maintain compatibility with clients which support only GET and POST such as older browsers,
Spring provides a filter
org.springframework.web.filter.HiddenHttpMethodFilter
to effectively tunnel any HTTP method through a POST request. If you intend to make use of
HTTP methods other than GET and POST in your handler mappings, add this filter to your CAE web
application's web.xml
or web-fragment.xml
:
<filter> <filter-name>HTTP Method Filter</filter-name> <filter-class> org.springframework.web.filter.HiddenHttpMethodFilter </filter-class> </filter> <filter-mapping> <filter-name>HTTP Method Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
With this filter in place, to signal the use of a particular HTTP method from the client, you
may send a POST request with an additional parameter indicating the HTTP method to use. By
default, the filter expects a parameter named _method
. Note that only
POST requests will be handled by this filter.
<form action="${url}" method="POST"> <input type="hidden" name="_method" value="PUT"/> ... </form>
Of course, clients supporting the HTTP method PUT, may send a PUT request directly, without
adding the _method
parameter.