Springboot轉(zhuǎn)發(fā)重定向?qū)崿F(xiàn)方式解析
1、轉(zhuǎn)發(fā)
方式一:使用 "forword" 關(guān)鍵字(不是指java關(guān)鍵字),注意:類的注解不能使用@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" 關(guān)鍵字(不是指java關(guān)鍵字),注意:類的注解不能使用@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()
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- springBoot熱部署、請求轉(zhuǎn)發(fā)與重定向步驟詳解
- springboot如何重定向外部網(wǎng)頁
- SpringBoot中處理的轉(zhuǎn)發(fā)與重定向方式
- springboot?實戰(zhàn):異常與重定向問題
- 使用springboot跳轉(zhuǎn)到指定頁面和(重定向,請求轉(zhuǎn)發(fā)的實例)
- springboot如何重定向攜帶數(shù)據(jù) RedirectAttributes
- springboot 重定向方式(redirect前綴)
- springboot項目攔截器重定向循環(huán)問題的解決
- 基于springboot redirect重定向路徑問題總結(jié)
- springboot 如何重定向redirect 并隱藏參數(shù)
- SpringBoot后端服務(wù)重定向的實現(xiàn)示例
相關(guān)文章
淺談SpringBoot中properties、yml、yaml的優(yōu)先級
優(yōu)先級低的配置會被先加載,所以優(yōu)先級高的配置會覆蓋優(yōu)先級低的配置,本文就來介紹一下SpringBoot中properties、yml、yaml的優(yōu)先級,感興趣的可以了解一下2023-08-08java 日志的數(shù)據(jù)脫敏的實現(xiàn)方法
今日給大家介紹一下java 日志的數(shù)據(jù)脫敏的實現(xiàn)方法,可以更好的保護數(shù)據(jù)的安全,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-01-01SpringBoot整合XxlJob分布式任務(wù)調(diào)度平臺
xxl-job是一個開源的分布式定時任務(wù)框架,它可以與其他微服務(wù)組件一起構(gòu)成微服務(wù)集群。它的調(diào)度中心(xxl-job)和執(zhí)行器(自己的springboot項目中有@XxlJob("定時任務(wù)名稱")的方法)是相互分離,分開部署的,兩者通過HTTP協(xié)議進行通信2023-02-02詳解Spring Cloud Zuul網(wǎng)關(guān)修改為短連接方法
本文主要介紹了詳解Spring Cloud Zuul網(wǎng)關(guān)修改為短連接方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04關(guān)于String.format()格式化輸出方式
String.format()是Java的格式化輸出方法,支持多種數(shù)據(jù)類型和格式化選項,它在格式化和拼接字符串時具有較高的靈活性,但效率相對較低,特別是在處理大量數(shù)據(jù)時,在實際編程中,應(yīng)根據(jù)具體需求選擇合適的字符串拼接方式2024-12-12Java實現(xiàn)動態(tài)規(guī)劃背包問題
本文主要介紹使用java實現(xiàn)動態(tài)規(guī)劃的背包問題,詳細使用圖文和多種案例進行解析,幫助理解該算法2021-06-06