[英]How to use Redirect in ModelAndView
我想將我的網址重定向到http:// localhost:8080 / ClickBuy / product / details到http:// localhost:8080 / ClickBuy / home 。
我已經定義了header.jsp並將其包含在我的所有Pages中。當我從其他任何地方點擊主頁鏈接url add / home從當前url.So它顯示404錯誤。
public ModelAndView allProduct()
{
ModelAndView model=new ModelAndView("pl");
model.addObject("data", pd.getAllProducts());
return model;
}
如何在ModelAndView中使用redirect:/返回類型方法???
要在ModelAndView返回類型方法中使用重定向:/,請嘗試以下操作
ModelAndView modelAndView = new ModelAndView("redirect:/abc.htm");
modelAndView.addObject("modelAttribute" , new ModelAttribute());
return modelAndView;
如果您不需要主頁中的任何模型,也可以使用String returntype返回主頁
@RequestMapping(value = "/home.htm", method = RequestMethod.GET)
public String homePage() {
return "home";
}
有不同的重定向方法,但使用Spring ModelView Object很簡單
@RequestMapping(value = "/redirecturl", method = RequestMethod.POST)
public ModelAndView methodPost() {
return new ModelAndView( "redirect:/login.html");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.