zoukankan      html  css  js  c++  java
  • AJAX发送PUT请求引发的血案

     如果直接发送ajax=put形式的请求
          是拿不到请求体中的数据的。
        
          Tomcat:
                  1、将请求体中的数据,封装一个map
                  2、request.getParameter("empName")就会从这个map中取值
                  3、SpringMVC封装POJO对象的时候
                          会把POJO中每个属性的值,request.getParameter("email");
          AJAX发送PUT请求引发的血案:
                  PUT请求:请求体中的数据,request.getParameter("empName")拿不到
                  Tomcat一看是PUT请求不会封装请求体中的数据为map,只有POST形式的请求才封装请求体为map
        
          tomcat源码中

    org.apache.catalina.connector.Request--parseParameters() (3000多行)
         
            protected String parseBodyMethods = "POST";
    if ( !getConnector().isParseBodyMethod(getMethod())){ success = true; return; }

     解决方法:

    1.ajax请求发送post方法,请求路径中+上 &_Method = PUT 或者

    2. 配置过滤器

       <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>
  • 相关阅读:
    metasploit-shellcode生成
    项目中遇到了docker、PaaS、k8s,它们之间的关系是怎么样的呢?
    docker是什么?它里面放着什么?
    java排序算法总结
    java类加载机制
    JVM垃圾回收算法
    跳出循环几种方式
    数据库分片分库常见问题解决方案
    数据库优化
    SQL生命周期
  • 原文地址:https://www.cnblogs.com/deepSleeping/p/10725177.html
Copyright © 2011-2022 走看看