【问题标题】:DELETE Representational State Transfer in Spring MVC在 Spring MVC 中删除表示状态传输
【发布时间】:2017-01-30 12:14:32
【问题描述】:

我有一个基于 Spring Web 模型-视图-控制器 (MVC) 框架的项目。 Spring Web 模型-视图-控制器 (MVC) 框架的版本是 3.2.8,部署在 WebLogic Server 版本上:12.1.2.0.0

我的 JSP 中有这段代码

<button id="deleteImageButtonId165850" class="btn btn-primary"  type="submit" >Delete Image</button>
<script>
$('#deleteImageButtonId165850').click(function(){$('#serviceFormId').attr('action', 'http://127.0.0.1:7001/devices/newdesign/manage/application/service/image/del/165850');
$('#serviceFormId').attr('method', 'delete');});
</script>

和我的控制器

@RequestMapping(value = { "/newdesign/manage/application/service/image/del/{imageId}",
                              "/newdesign/manage/application/service/image/del/{imageId}/" }, method = { RequestMethod.DELETE })
    public String deleteServiceImage(@ModelAttribute("serviceForm") ServiceForm serviceForm, @PathVariable Long imageId,
                                    HttpServletRequest request, Model model) throws Exception {
..
}

但是当我点击按钮时,我得到了一个

Request method 'GET' not supported

【问题讨论】:

    标签: java spring spring-mvc


    【解决方案1】:

    HTML 表单只支持 GET 和 POST。 您必须在 JavaScript 中执行 DELETE。

    【讨论】:

      【解决方案2】:

      测试以下代码

      @RequestMapping(value = { "/newdesign/manage/application/service/image/del/{imageId}",
                                    "/newdesign/manage/application/service/image/del/{imageId}/" }, method = { RequestMethod.POST })
          public String deleteServiceImage(@ModelAttribute("serviceForm") ServiceForm serviceForm, @PathVariable Long imageId,
                                          HttpServletRequest request, Model model) throws Exception {
      ..
      }
      

      【讨论】:

        猜你喜欢
        • 2015-05-14
        • 2013-12-15
        • 2013-05-31
        • 1970-01-01
        • 2023-01-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-08
        相关资源
        最近更新 更多