已经在web.xml中配置过滤器,为何无法提交put请求?
web.xml中配置过滤器
<filter>
<filter-name>HiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HiddenHttpMethodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
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 ResponseEntity<Void> updateItem(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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
405 Method Not Allowed*:说明服务不存在。
确定处理类没有缺少声明@Controller
指定请求的实际地址:
@RequestMapping(value = "/rest/item",method = RequestMethod.PUT)
应该是RequestMapping value没写
有可能是你的路径写错了(js 里面)
参见:http://bbs.csdn.net/topics/39...
4** 这样的异常一般是路径不对