使用springMVC时遇到的HTTP Status 405

来源:互联网 发布:windows 可以写多进程 编辑:程序博客网 时间:2024/06/05 22:46

先看看问题的详情:


第一眼会觉得这是一个很好解决的问题,我写的controller方法中的确是限定了其不能通过GET方式请求url:

@RequestMapping(value = "isLoginValid", method = { RequestMethod.POST })

但是在前端使用JQuery AJax我的确是没有用GET方式提交数据:

$.ajax({type : 'POST',url : '/TrainingProgramManager/isLoginValid.html',data : {username : username,password : $.md5(password)},success : function(result) {if (result) {// 重定向到系统首页中window.location = '/TrainingProgramManager/loadIndex.html';} else {$.messager.alert('错误','用户名或密码错误');}}});
后面发现问题出在:我访问的方法使用了@ResponseBody,而后缀名为html,这里就出现了后缀名冲突的问题(可能是springMVC的视图解析器无法正确解析了),同理的还有htm,json,php等等,所有我们只要在前端控制器的url-pattern里面更换一个后缀名问题就解决了。





0 0