zoukankan      html  css  js  c++  java
  • 解决SpringMVC put,patch,delete请求数据拿不到的问题

    解决SpringMVC put,patch,delete请求参数拿不到的问题

    废话不多说,核心代码如下:

    在web.xml中添加如下代码

        <!-- 解决web端不能put,delete等请求的问题 -->
        <filter>
            <filter-name>HiddenHttpMethodFilter</filter-name>
            <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
        </filter>
        <filter-mapping>
            <filter-name>HiddenHttpMethodFilter</filter-name>
            <servlet-name>springMVC</servlet-name>
        </filter-mapping>
    <!-- 解决put,patch等请求,data数据拿不到的问题 --> <filter> <filter-name>HttpPutFormContentFilter </filter-name> <filter-class>org.springframework.web.filter.HttpPutFormContentFilter</filter-class> </filter> <filter-mapping> <filter-name>HttpPutFormContentFilter </filter-name> <servlet-name>springMVC</servlet-name> </filter-mapping>

    我的环境是Spring4.3;

    第一个filter是解决 jQuery不能put,patch等请求,但是我测试用的 jquery-3.1.1.js 是可以put,patch请求的;可能是前端用的js版本低了吧,我也没研究;

    但是put,patch等请求,data数据后台拿不到的问题,但是拼接到URL里面就可以拿到;第二个filter就解决这个问题;

    顺便记录一个通过Spring解决跨域访问的问题

    在spring-mvc.xml中添加如下代码:

      <!-- 添加跨域访问 -->
        <mvc:cors>
            <mvc:mapping path="/**" allowed-origins="*" allowed-methods="*" allowed-headers="*" allow-credentials="false" max-age="3600"  />
        </mvc:cors>

    参考:https://blog.csdn.net/edison_03/article/details/76150906

      https://blog.csdn.net/lankezhou/article/details/72491019

  • 相关阅读:
    Python_base_局部变量和全局变量
    Python_base_id()函数
    登录的测试点
    Http协议
    python_base_while循环、for循环
    <10>Golang基础进阶——函数
    <7>Golang基础进阶——流程控制
    Could not connect to SFTP server at "sftp://x.x.x.x:22/"
    <5>Golang基础进阶——类型别名
    <4>Golang基础进阶——字符串应用
  • 原文地址:https://www.cnblogs.com/jr1260/p/9152275.html
Copyright © 2011-2022 走看看