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

  • 相关阅读:
    js正则表达式基本语法
    类似于QQ的右滑删除效果的实现方法
    JS设置cookie、读取cookie、删除cookie
    JavaScript随机生成颜色的方法
    mysql数据库备份及恢复
    Javascript 实现简单计算器实例代码
    JavaScript 实现的checkbox经典实例分享
    网页瀑布流布局jQuery实现代码
    Django Web在Apache上的部署
    VIM使用系列之一——配置VIM下C/C++编程环境
  • 原文地址:https://www.cnblogs.com/jr1260/p/9152275.html
Copyright © 2011-2022 走看看