java HTTP 状态 405 - 在 spring mvc 中返回“redirect:*.*”时不支持请求方法“GET”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32986640/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTTP Status 405 - Request method 'GET' not supported when doing return "redirect:*.*" in spring mvc
提问by romil gaurav
In spring MVC... I have to reload a page after the record is updated. So in the action method I am returning String and in return I am returning
在 spring MVC 中...我必须在记录更新后重新加载页面。所以在 action 方法中我返回 String 而作为回报我返回
return "redirect:/recordList";
When but it is giving the exception on the page
当但它在页面上给出异常
HTTP Status 405 - Request method 'GET' not supported
There is no exception coming on the logs.
日志上也不例外。
My controller method looks like
我的控制器方法看起来像
@RequestMapping(value= "/recordList", method = RequestMethod.POST)
public ModelAndView getAssetListForUser(@RequestParam("ldapId") String ldapId,
final HttpServletRequest request){
Also, because I need the value if ldapId in the controller method, I am binding it in the calling method like this
另外,因为我需要控制器方法中的 ldapId 值,所以我将它绑定到调用方法中
request.setAttribute("ldapId", assetAssetEmp.getAssetEmpId());
Please help.
请帮忙。
回答by Raja Nadar
It looks like your /recordList
controller method only supports RequestMethod.POST
.
hence you're getting the 405 GET Method not allowed error, since the redirect will issue a GET request.
看起来您的/recordList
控制器方法仅支持RequestMethod.POST
. 因此您会收到 405 GET Method not allowed 错误,因为重定向将发出 GET 请求。
to solve for it, try to give a GET version of your controller action. (the assetlist method) so that once the update happens, the asset list of the user can be returned via the GET method.
要解决它,请尝试提供控制器操作的 GET 版本。(资产列表方法),以便一旦发生更新,可以通过 GET 方法返回用户的资产列表。
回答by Ankur Singhal
The @RequestMapping
annotation is your way to specify when your method is going to be called in an annotated controller. The RequestMethod.GET
and RequestMethod.POST
arguments allow you to respond to the specific HTTP
request type.
该@RequestMapping
注释是你当你的方法是要在注释控制器被称为指定的方式。在RequestMethod.GET
和RequestMethod.POST
参数允许您具体回应HTTP
请求类型。
providing method = RequestMethod.POST
to controller method actually making method to accept only HTTP POST
requests.
提供method = RequestMethod.POST
给控制器方法实际上使方法只接受HTTP POST
请求。