码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-03-27 10:31:56      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:ret   ram   parameter   frame   解决方法   string   lte   system   aaa   

@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>

 

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

标签:ret   ram   parameter   frame   解决方法   string   lte   system   aaa   

原文地址:http://www.cnblogs.com/webtj/p/6625408.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!