众所周知,SpringMVC的Controller方法通过返回view,然后结合viewResolver,最终跳转到指定目录的jsp。如果想在Controller的业务方法中跳转到不同的目录,例如跳转到dept中hello.jsp中。本文主要介绍SpringMVC在Controller的业务方法中如何跳转到不同的jsp目录。
原理:在Controller的业务方法中指定"跳转的目录"+“目标JSP名称”。
webContent视图:
springMVC-servlet.xml
controller
@RequestMapping(value="hello.action")
protected String hello(HttpServletRequest request,
HttpServletResponse response,Model model,User user) throws Exception {
// 跳转到dept中的hello.jsp
return "dept/hello";
}
@RequestMapping(value="hello.action")
protected String hello(HttpServletRequest request,
HttpServletResponse response,Model model,User user) throws Exception {
// 跳转到goods中的car.jsp
return "goods/car.jsp";
}