Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can i set the url before returning the ModelAndView?

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

like image 685
randy Avatar asked Dec 01 '10 05:12

randy


2 Answers

Try instantiating your ModelAndView like this,

ModelAndView model = new ModelAndView(new RedirectView("contact"));
like image 74
Adeel Ansari Avatar answered Oct 21 '22 09:10

Adeel Ansari


The approved answer didn't work for me.

This did:

ModelAndView model = new ModelAndView("dashboard");
model.setViewName("redirect:dashboard.html");
like image 23
Michael Singer Avatar answered Oct 21 '22 10:10

Michael Singer