![](/img/trans.png)
[英]How to get the POST request parameters of a jQuery $.post from a spring mvc controller?
[英]Change the request method from POST to GET in a redirection from spring controller
我有一個 spring mvc 控制器,它接受一個 post 請求,它需要重定向到一個 URL(GET 請求)。
@RequestMapping(value = "/sredirect", method = RequestMethod.POST)
public String processForm(HttpServletRequest request) {
System.out.println("Ews redirect hit !!! ");
request.setAttribute(View.RESPONSE_STATUS_ATTRIBUTE,HttpStatus.MOVED_PERMANENTLY);
return "redirect:https://www.google.com/";
}
並且該類使用@RestController 進行了注釋。 我總是收到 405,重定向 url 不允許的方法。 (即 google.com)。
根據文檔( https://tools.ietf.org/html/rfc7238 ),它應該允許更改方法。 我不確定我做錯了什么? 有人可以幫忙嗎
看起來 Rest 控制器不能像非 Rest 控制器那樣使用簡單的“重定向:”約定。 查看Spring MVC @RestController 並重定向
您是否嘗試過在請求映射中接受 GET?
method = { RequestMethod.POST, RequestMethod.GET }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.