zoukankan      html  css  js  c++  java
  • Spring MVC Restful Put方法无法获取参数值

    Spring MVC Restful 无法通过@ReqeustParam获取参数值

    原因是Tomcat只支持POST/GET获取参数值,对于PUT这些方法需要通过HttpPutFormContentFilter对其进行拦截过滤,该filter内部通过HttpServletRequestWrapper将参数塞进request的param中。

    • 解决该问题只需要在项目web.xml中加入代码:

    <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的HiddenHttpMethod

    加入如下代码:

    
    
    <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>
  • 相关阅读:
    寒假学习记录07
    寒假学习记录06
    寒假学习记录05
    寒假学习记录04
    寒假学习记录03
    寒假学习记录02
    寒假学习记录01
    河北省重大技术需求征集系统(13)
    学习进度(4)
    学习进度(3)
  • 原文地址:https://www.cnblogs.com/zhengshiqiang47/p/7553079.html
Copyright © 2011-2022 走看看