Redirect from spring controller with post parameter

I want to redirect to another page (outside my application) from a spring controller with the post parameter. I searched a lot, but did not find a solution.

+8
redirect spring
source share
3 answers

You cannot add POST, but you can redirect using GET. Follow these steps:

@RequestMapping("/redirectMe") public void redirectMe (HttpServletResponse response){ response.sendRedirect("http://redirected.com/form?someGetParam=foo"); } 
+4
source share

Do something like this

 @RequestMapping(value="/someUrl",method=RequestMethod.POST) public String myFunc(HttpServletRequest request,HttpServletResponse response,Map model){ //do sume stuffs return "redirect:/anotherUrl"; //gets redirected to the url '/anotherUrl' } @RequestMapping(value="/anotherUrl",method=RequestMethod.GET) public String myAnotherFunc(HttpServletRequest request,HttpServletResponse response){ //do sume stuffs return "someView"; } 
+1
source share

easy way to do:

  @PostMapping("/redirectPostToPost") public ModelAndView redirectPostToPost(HttpServletRequest request) { request.setAttribute( View.RESPONSE_STATUS_ATTRIBUTE, HttpStatus.TEMPORARY_REDIRECT); return new ModelAndView("redirect:/redirectedPostToPost"); } @PostMapping("/redirectedPostToPost") public ModelAndView redirectedPostToPost() { return new ModelAndView("redirection"); } 
0
source share

All Articles