Redirect from spring controller with post parameter
18,140
Solution 1
You will not be able to add a POST, but you can redirect with GET. Do the following:
@RequestMapping("/redirectMe")
public void redirectMe (HttpServletResponse response){
response.sendRedirect("http://redirected.com/form?someGetParam=foo");
}
Solution 2
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";
}
Related videos on Youtube
Author by
dmay
Updated on June 04, 2022Comments
-
dmay almost 2 years
I want to redirect to another page(outside my application) from spring controller with post parameter. I search a lot but didn't any solution.
-
Betlista about 12 yearsWhy post is not possible? I have problem with get when I have collection as parameter generated URL is then:
http://localhost:8080/myApp/A/result.form?parameters=SomeName¶meters=SoemField
which leads toparameters=SomeName
. Any idea? -
aweigold about 12 yearsWhen you advise the browser to redirect, as is stated in this question, there is nowhere to define which http verb is being used. It will always be a GET. If you need to POST, you will need to deploy a javascript client to do so, and you will need to make sure you are not doing cross site scripting.