• 解决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

  • 相关阅读:
    Netty源码分析之ByteBuf引用计数
    GitHub git push大文件失败(write error: Broken pipe)完美解决
    Windows10 Docker安装详细教程
    全面的Docker快速入门教程
    十本你不容错过的Docker入门到精通书籍推荐
    CentOS 8.4安装Docker
    postgres之一条sql查询总数及部分数据
    neo4j相关操作
    git上传大文件
    分布式文件系统fastdfs安装以及python调用
  • 原文地址:https://www.cnblogs.com/jr1260/p/9152275.html
Copyright © 2020-2023  润新知