开发者

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 mo开发者_开发知识库del, 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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜