请求转发:在同一个controller将请求转发到另一个请求映射,请求地址不会发生改变
//请求转发
@RequestMapping("/testFoeward")
//@ResponseBody
public String testforWard1() {
System.out.println("testforWard1执行了");
return"forward:/test";// 请求转发到/test
}
@RequestMapping("/test")
public String testforWard2() {
System.out.println("testforward2执行了");
return"hello";//跳转到hello.jsp
}

重定向:将请求重定向到不同的controller
//重定向
/*
* (1)可以从当前controller中的方法重定向到另一个controller方法
* [return " redirect:/资源路径"]
* 请求转发路径会发生改变
*/
@RequestMapping("/testRedirect")
public String testredirect1() {
System.out.println("testRedirect执行了");
return "redirect:http://localhost:8080/day_22/test";
//return "redirect:http://www.baidu.com";重定向到百度
}


网友评论