can i set the url before returning the ModelAndView?

可紊 提交于 2020-01-04 01:58:32

问题


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


回答1:


Try instantiating your ModelAndView like this,

ModelAndView model = new ModelAndView(new RedirectView("contact"));



回答2:


The approved answer didn't work for me.

This did:

ModelAndView model = new ModelAndView("dashboard");
model.setViewName("redirect:dashboard.html");


来源:https://stackoverflow.com/questions/4321517/can-i-set-the-url-before-returning-the-modelandview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!