請求轉發:在同一個controller將請求轉發到另一個請求映射,請求地址不會發生改變
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
//請求轉發 @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
2
3
4
5
6
7
8
9
10
11
12
|
//重定向 /* * (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";重定向到百度 } |
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:https://www.cnblogs.com/syrgdm/p/13360986.html