ajax请求无法被过滤器,已经在web.xml中配置过滤器,为何无法提交put请求?

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值