久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

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

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

瀏覽:2日期: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
相關文章:
主站蜘蛛池模板: 岳普湖县| 焉耆| 顺昌县| 长垣县| 泸溪县| 怀集县| 和林格尔县| 唐河县| 阿勒泰市| 文化| 清丰县| 涡阳县| 易门县| 青龙| 桐乡市| 天祝| 宁波市| 苗栗市| 屯门区| 开鲁县| 新乡市| 三原县| 忻州市| 若尔盖县| 名山县| 绥芬河市| 柘城县| 和田市| 准格尔旗| 包头市| 花莲县| 大关县| 洛南县| 梧州市| 会泽县| 津南区| 中山市| 柳州市| 民权县| 通州区| 龙里县|