Spring MVC ,无法请求以PUT ,DELETE等为 http方式的解决方法


@RequestMapping(value = "/test1.do",method = RequestMethod.DELETE)
public String testMapping1(HttpServletRequest request, HttpServletResponse response, ModelMap map){
    System.out.println("tj==========11==========test");
    String loginparams=request.getParameter("loginparams");
    System.out.println("tj=============loginparams================="+loginparams);
    map.put("tj","aaaaaa");

    return "test1";
}

  

method = RequestMethod.DELETE 时候,前端 跳转至 test1.do,type="DELETE",无法进入该方法
            $.ajax({
                  type: "DELETE",  //方式为DELETE,进不来
                  url: "/test1.do",
                  //data:"loginparams="+JSON.stringify({"name":"taojian","age":18}),
                  data:{"loginparams":[{"name":"taojian","age":18}]},
                  success: function(data){
                      alert(data)
                  }
              });

  

解决方法: web.xml 增加下面过滤器

<!--可以请求到 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>dispatcher</servlet-name>
</filter-mapping>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM