Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to set the url in a spring mvc controller?

User_VQ1Z5Nov 12 2020

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?

Comments

Post Details

Added on Nov 12 2020
0 comments
161 views