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

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

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

瀏覽:8日期: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
相關文章:
主站蜘蛛池模板: 鲁甸县| 乳源| 共和县| 义马市| 鄂伦春自治旗| 太原市| 浦江县| 西藏| 郴州市| 佛冈县| 襄垣县| 丹寨县| 岳阳县| 莫力| 沛县| 宁阳县| 莱西市| 松潘县| 库尔勒市| 溧阳市| 临颍县| 潍坊市| 喀喇沁旗| 绍兴县| 海门市| 祁东县| 二连浩特市| 乌拉特中旗| 南川市| 陇川县| 南部县| 淮滨县| 固原市| 南平市| 遵义市| 通海县| 隆尧县| 北川| 南通市| 玉环县| 阳城县|