国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

Springboot轉發重定向實現方式解析

瀏覽:3日期:2023-05-29 14:41:33

1、轉發

方式一:使用 '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()

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Spring
相關文章:
主站蜘蛛池模板: 玉龙| 哈密市| 淳化县| 石景山区| 年辖:市辖区| 夹江县| 凤山县| 琼结县| 霍州市| 滕州市| 雅安市| 夏津县| 来宾市| 长岭县| 堆龙德庆县| 常宁市| 嘉义市| 清丰县| 临泉县| 拜城县| 岳阳县| 奉节县| 彩票| 香河县| 永康市| 固镇县| 丹寨县| 信宜市| 罗山县| 伽师县| 黄陵县| 聂荣县| 水城县| 江门市| 普安县| 米脂县| 双鸭山市| 铜梁县| 延津县| 榆树市| 苗栗县|