web.xml中配置过滤器
HiddenHttpMethodFilter org.springframework.web.filter.HiddenHttpMethodFilter HiddenHttpMethodFilter /*
jsp中使用put提交ajax请求
//提交到后台的RESTful $.ajax({ type: "PUT", url: "/rest/item", data: $("#itemeEditForm").serialize(), statusCode:{ 204:function(){ $.messager.alert('提示','修改商品成功!','info',function(){ $("#itemEditWindow").window('close'); $("#itemList").datagrid("reload"); }); }, 500:function(){ $.messager.alert('提示','修改商品失败!'); } } });
后端controller接受请求
@RequestMapping(method = RequestMethod.PUT) public ResponseEntityupdateItem(Item item, @RequestParam("desc") String desc){ try { this.itemService.updateItem(item,desc); //200 return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); } catch (Exception e) { e.printStackTrace(); logger.error("修改商品出错"); } //500 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); }
控制台输出错误
2016-11-29 19:10:32,408 [http-bio-8080-exec-9] [org.springframework.web.servlet.DispatcherServlet]-[DEBUG] DispatcherServlet with name 'taotao-manage' processing PUT request for [/rest/item] 2016-11-29 19:10:32,408 [http-bio-8080-exec-9] [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping]-[DEBUG] Looking up handler method for path /item 2016-11-29 19:10:32,408 [http-bio-8080-exec-9] [org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver]-[DEBUG] Resolving exception from handler [null]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported 2016-11-29 19:10:32,408 [http-bio-8080-exec-9] [org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver]-[DEBUG] Resolving exception from handler [null]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported 2016-11-29 19:10:32,408 [http-bio-8080-exec-9] [org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver]-[DEBUG] Resolving exception from handler [null]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported 2016-11-29 19:10:32,409 [http-bio-8080-exec-9] [org.springframework.web.servlet.PageNotFound]-[WARN] Request method 'PUT' not supported 2016-11-29 19:10:32,409 [http-bio-8080-exec-9] [org.springframework.web.servlet.DispatcherServlet]-[DEBUG] Null ModelAndView returned to DispatcherServlet with name 'taotao-manage': assuming HandlerAdapter completed request handling 2016-11-29 19:10:32,409 [http-bio-8080-exec-9] [org.springframework.web.servlet.DispatcherServlet]-[DEBUG] Successfully completed request
浏览器显示
Request URL:http://localhost:8080/rest/item Request Method:PUT Status Code:405 Method Not Allowed Remote Address:[::1]:8080
有可能是你的路径写错了(js 里面)
参见:http://bbs.csdn.net/topics/39...
4** 这样的异常一般是路径不对
应该是RequestMapping value没写
确定处理类没有缺少声明@Controller
指定请求的实际地址:
@RequestMapping(value = "/rest/item",method = RequestMethod.PUT)