• 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>
  • 相关阅读:
    3月4日毕设进度
    3月3日毕设进度
    3月2日毕设进度
    3月1日毕设进度
    2月29日毕设进度
    2月28日毕设进度
    2月27日毕设进度
    进度报告七 (重大技术需求调研)
    进度报告六-(重大技术需求调研)
    进度报告五 (重大技术需求调研)
  • 原文地址:https://www.cnblogs.com/deepSleeping/p/10725177.html
Copyright © 2020-2023  润新知