Reputation: 1456
I have a spring mvc controller, which accepts a post request and it needs to redirect to a URL (GET request).
@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/";
}
And the class is annotated with @RestController. I am always getting 405, method not allowed for the redirect url. (i.e google.com).
As per docs (https://www.rfc-editor.org/rfc/rfc7238), it should allow the method to be changed . I am not sure what am I doing wrong? Can someone help
Upvotes: 1
Views: 4218
Reputation: 5105
It looks like Rest Controllers can't use the simple "redirect:" convention, like non-Rest Controllers can. See Spring MVC @RestController and redirect
Upvotes: 1
Reputation: 76
Have you tried accepting GET in the request mapping?
method = { RequestMethod.POST, RequestMethod.GET }
Upvotes: 0