Forum Stats

  • 3,722,782 Users
  • 2,244,412 Discussions
  • 7,850,085 Comments

Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

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:
Sign In or Register to comment.