Request forwarding: When the same controller forwards the request to another request mapping, the request address will not change
//请求转发
@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
}
Redirection: redirect the request to a different 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";重定向到百度
}