@org.springframework.stereotype.Controller @RequestMapping("/userController") public class UserController{ @RequestMapping("/handler1") public String handler1() throws IOException { //转发给handler2处理 return "forward:handler2"; } @RequestMapping("/handler2") public void handler2(HttpServletResponse response) throws IOException { //...... } }
返回String,在里面加上关键字:forward(转发),redirect(重定向)。html
(1)若是是转发、重定向到本controller的其它业务方法:web
return "forward:/userController/handler2";
无论handler2()是标注为@RequestMapping("/handler2"),仍是标注为@RequestMapping("handler2"),都只能这样:spring
return "forward:handler2";
(2)若是是转发、重定向到其它controller的业务方法,只能写全路径。mvc
springmvc原本就会把返回的字符串做为视图名解析,而后转发到对应的视图。app
转发有2种方式:jsp
重定向:spa
由于使用关键字forward、redirect时,SpringMVC不会使用视图解析器来解析视图名,也就不能使用视图名拼接,只能写全路径。code
在web文件夹下新建1.jsphtm
return "redirect:/1.jsp";
/表示web文件夹根目录。blog
能够转发、重定向到html这种静态页面,也能够转发、重定向到WEB-INF下的页面,但须要配置资源,
参考:http://www.javashuo.com/article/p-qgcprrlt-o.html
固然,也能够使用servlet的方式来实现: