Springboot轉發(fā)重定向實現(xiàn)方式解析
1、轉發(fā)
方式一:使用 "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熱部署、請求轉發(fā)與重定向步驟詳解
- springboot如何重定向外部網頁
- SpringBoot中處理的轉發(fā)與重定向方式
- springboot?實戰(zhàn):異常與重定向問題
- 使用springboot跳轉到指定頁面和(重定向,請求轉發(fā)的實例)
- springboot如何重定向攜帶數(shù)據(jù) RedirectAttributes
- springboot 重定向方式(redirect前綴)
- springboot項目攔截器重定向循環(huán)問題的解決
- 基于springboot redirect重定向路徑問題總結
- springboot 如何重定向redirect 并隱藏參數(shù)
- SpringBoot后端服務重定向的實現(xiàn)示例
相關文章
http basic authentication通過post方式訪問api示例分享 basic認證示例
在HTTP中,基本認證是一種用來允許Web瀏覽器或其他客戶端程序在請求時提供以用戶名和口令形式的憑證,這篇文章主要介紹了http basic authentication通過post方式訪問api示例,大家參考使用吧2014-01-01
搭建 springboot selenium 網頁文件轉圖片環(huán)境的詳細教程
這篇文章主要介紹了搭建 springboot selenium 網頁文件轉圖片環(huán)境,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-08-08
Spring Security LDAP實現(xiàn)身份驗證的項目實踐
在本文中,我們涵蓋了“使用 Spring Boot 的 Spring Security LDAP 身份驗證示例”的所有理論和示例部分,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-08-08
maven打生產環(huán)境可執(zhí)行包的實現(xiàn)
本文主要介紹了maven打生產環(huán)境可執(zhí)行包的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2025-01-01
Springboot基于maven打包分離lib及resource
這篇文章主要介紹了Springboot基于maven打包分離lib及resource,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-10-10

