Arat Kumar rana
Arat Kumar rana

Reputation: 187

redirect from get method to post method in spring controller

I have a link retailerId after clicking the link control will go to the below controller:

@Controller
@RequestMapping(value = "/auth/adminsearchowner")
public class AdminSearchOwnerController {

 @RequestMapping(value = "/retailerId/{retailerId}",method = RequestMethod.GET)
public ModelAndView viewRetailerInfo(
        @PathVariable("retailerId") String retailerId,
        @ModelAttribute EditRetailerLifeCycleBean editLicenseBean) {
    editLicenseBean.setSelectedIDsString(retailerId);
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.addObject("editLicenseBean",editLicenseBean);
    modelAndView.setViewName("redirect:/auth/adminlicense/viewlicense");
    return modelAndView;
  } 
}

where /auth/adminlicense/viewlicense is in another controller and we have both GET and POST method for this /auth/adminlicense/viewlicense request mapping. I want to call the post method from the earlier controller.

@Controller
@RequestMapping("/auth/adminlicense")
public class AdminViewLicenseController {

@RequestMapping(value = "/viewlicense", method = RequestMethod.GET)
public ModelAndView searchRetailerLicense(
        @ModelAttribute("editLicenseBean") EditRetailerLifeCycleBean editLicenseBean,
        HttpSession session) {
  }

@RequestMapping(value = "/viewlicense", method = RequestMethod.POST)
public ModelAndView getLicenseDetails(
        @ModelAttribute EditRetailerLifeCycleBean lifeCycleBean,
        HttpSession session) {
  }
 }

but it is going to GET method. Could you tell me the solution?

Upvotes: 0

Views: 2543

Answers (2)

pisek
pisek

Reputation: 1439

Try:

modelAndView.setViewName("forward:/auth/adminlicense/viewlicense");

instead of

modelAndView.setViewName("redirect:/auth/adminlicense/viewlicense");

A design in which you are trying to send some data from one controller(server-side) to another(server-side) via user's browser(client-side) is probably not the best idea, anyway.

Hope it helps!

Upvotes: 0

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 279930

There is no solution. A redirect cannot cause a POST to be sent by the browser.

Rethink your design.

Upvotes: 2

Related Questions