Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect from spring controller with post parameter

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.

like image 518
dmay Avatar asked Jan 30 '12 20:01

dmay


2 Answers

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");
}
like image 175
aweigold Avatar answered Sep 23 '22 14:09

aweigold


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"; 
}
like image 28
Moinul Hossain Avatar answered Sep 24 '22 14:09

Moinul Hossain