is it possible to set your url before returning your model?
For example, my current url is http://localhost/home.html at my homecontroller, I return a modelandview for another page, for example
ModelAndView model = new ModelAndView("contact");
model.addObject("contactNo", "12345");
return model;
then after returning the model, my contact.jsp has been loaded to my browser but it's url is still http://localhost/home.html, I want to change it to http://localhost/contact.html, how can i able to do that?
thanks
Try instantiating your ModelAndView
like this,
ModelAndView model = new ModelAndView(new RedirectView("contact"));
The approved answer didn't work for me.
This did:
ModelAndView model = new ModelAndView("dashboard");
model.setViewName("redirect:dashboard.html");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With