五、客户端跳转
在前面的例子中,无论是/index跳转到index.jsp 还是/addProduct 跳转到showProduct.jsp,都是服务端跳转
1、修改IndexController
首先映射/jump到jump()方法,在jump()中编写如下代码
ModelAndView mav = new ModelAndView("redirect:/index");
@Controller
public class IndexController {
@RequestMapping("/index")
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
ModelAndView mav = new ModelAndView("index");
mav.addObject("message", "Hello Spring MVC");
return mav;
}
@RequestMapping("/jump")
public ModelAndView jump() {
//redirect:/index,即表示客户端跳转的意思
ModelAndView mav = new ModelAndView("redirect:/index");
return mav;
}
}
2、访问页面
结果客户端跳转到了