坑爹的SpringMVC-控制器接收不了PUT请求

结论:SpringMVC对REST支持不好,不支持PUT,DELETE方法,PATCH压根,就没有定义。那些说某些浏览器不支持这些方法的人,你说连IE,chrome,fireFox都不支持,还做个屁web。我抓了发送的请求,里面有包含参数。

前言

项目在用SpringMVC做REST,前台用$ajax发PUT方法,Controller中@RequestMapping( method = RequestMethod.PUT)死活进不了。

最后在web.xml中配置了HttpPutFormContentFilter才解决。

 <filter> 
    <filter-name>httpPutFormcontentFilter</filter-name> 
    <filter-class>org.springframework.web.filter.HttpPutFormContentFilter</filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>httpPutFormContentFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping>

        在Spring MVC过滤器-HiddenHttpMethodFilter中我们提到,jsp或者说html中的form的method值只能为post或get,我们可以通过HiddenHttpMethodFilter获取put表单中的参数-值,而在Spring3.0中获取put表单的参数-值还有另一种方法,即使用HttpPutFormContentFilter过滤器。

        HttpPutFormContentFilter过滤器的作为就是获取put表单的值,并将之传递到Controller中标注了method为RequestMethod.put的方法中。

        在web.xml中配置HttpPutFormContentFilter的代码类似如下:

 

你可能感兴趣的:(springMVC,REST,Spring3.11,jquery1.11)