1、轉發

成都創新互聯公司是一家業務范圍包括IDC托管業務,虛擬主機、主機租用、主機托管,四川、重慶、廣東電信服務器租用,成都IDC機房托管,成都網通服務器托管,成都服務器租用,業務范圍遍及中國大陸、港澳臺以及歐美等多個國家及地區的互聯網數據服務公司。
方式一:使用 "forword" 關鍵字(不是指java關鍵字),注意:類的注解不能使用@RestController 要用@Controller
@RequestMapping(value="/test/test01/{name}" , method = RequestMethod.GET)
public String test(@PathVariable String name) {
return "forword:/ceng/hello.html";
}方式二:使用servlet 提供的API,注意:類的注解可以使用@RestController,也可以使用@Controller
@RequestMapping(value="/test/test01/{name}" , method = RequestMethod.GET)
public void test(@PathVariable String name, HttpServletRequest request, HttpServletResponse response) throws Exception {
request.getRequestDispatcher("/ceng/hello.html").forward(request,response);
}2、重定向
方式一:使用 "redirect" 關鍵字(不是指java關鍵字),注意:類的注解不能使用@RestController,要用@Controller
@RequestMapping(value="/test/test01/{name}" , method = RequestMethod.GET)
public String test(@PathVariable String name) {
return "redirect:/ceng/hello.html";
}方式二:使用servlet 提供的API,注意:類的注解可以使用@RestController,也可以使用@Controller
@RequestMapping(value="/test/test01/{name}" , method = RequestMethod.GET)
public void test(@PathVariable String name, HttpServletResponse response) throws IOException {
response.sendRedirect("/ceng/hello.html");
}使用API進行重定向時,一般會在url之前加上:request.getContextPath()
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持創新互聯。
網站名稱:Springboot轉發重定向實現方式解析
網頁網址:http://www.yijiale78.com/article30/pehjpo.html
成都網站建設公司_創新互聯,為您提供網站維護、品牌網站制作、網站收錄、面包屑導航、自適應網站、用戶體驗
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯