PUT请求,请求体中的数据 request.getParameter(“empName”) 拿不到。
Tomcat 一看是PUT不会封装请求体中的数据 为map 只有为POST形式的请求才封装请求体为map。
我们要能支持 直接发送PUT之类的请求还要封装请求体中的数据
在web.xml中添加 HttpPutFormContentFilter 过滤器
<!-- 解决put请求 数据封装 -->
<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>
作用 :
将请求体中的数据解析包装成一个map,request被重新包装,request.getParameter()被重写 。
如果 request.getParameter()取不到 就会从自己封装的map中取数据。
Controller层代码: