Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I Want to redirect my url to http://localhost:8080/ClickBuy/product/details to http://localhost:8080/ClickBuy/home .

I have Define header.jsp and Include it in all my Pages.When I click home link from anywhere else url add /home from current url.So it shows 404 error.

Controller

public ModelAndView allProduct()
{   
ModelAndView model=new ModelAndView("pl");
model.addObject("data", pd.getAllProducts());
return model;
}

How can I use redirect:/ in ModelAndView return type method???

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
379 views
Welcome To Ask or Share your Answers For Others

1 Answer

To Use redirect:/ in ModelAndView return type method, you are try following

ModelAndView modelAndView =  new ModelAndView("redirect:/abc.htm");
modelAndView.addObject("modelAttribute" , new ModelAttribute());
return modelAndView;

You can also return home page using String returntype if you do not need any Model in home page

@RequestMapping(value = "/home.htm", method = RequestMethod.GET)
   public String homePage() {
      return "home";
   }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...