Forum Stats

  • 3,840,393 Users
  • 2,262,599 Discussions
  • 7,901,261 Comments

Discussions

How to set the url in a spring mvc controller?

I have a form with several fields and a save button.

When the save button is clicked, the form is submitted and the following spring mvc controller is executed.


@RequestMapping(method = RequestMethod.POST, value = "/saveform1")

public ModelAndView savePerson(Person person) {

   personRepository.save(person);

  ModelAndView modelAndView = new ModelAndView("form2");

  modelAndView.addObject("personobj", person);

  return modelAndView;

 }


The controller correctly saves the data and opens form2. It also correctly populates form2 fields with data from personobj.

The problem is that, at this point the url should be localhost:8080/form2 because the content for form2 is being displayed. But instead, the url is displaying localhost:8080/saveform1.

How can I set the url to be localhost:8080/form2?

Tagged: