欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Springboot轉(zhuǎn)發(fā)重定向?qū)崿F(xiàn)方式解析

1、轉(zhuǎn)發(fā)

成都創(chuàng)新互聯(lián)公司是一家業(yè)務范圍包括IDC托管業(yè)務,虛擬主機、主機租用、主機托管,四川、重慶、廣東電信服務器租用,成都IDC機房托管,成都網(wǎng)通服務器托管,成都服務器租用,業(yè)務范圍遍及中國大陸、港澳臺以及歐美等多個國家及地區(qū)的互聯(lián)網(wǎng)數(shù)據(jù)服務公司。

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

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

網(wǎng)站名稱:Springboot轉(zhuǎn)發(fā)重定向?qū)崿F(xiàn)方式解析
網(wǎng)頁網(wǎng)址:http://chinadenli.net/article30/pehjpo.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護、品牌網(wǎng)站制作、網(wǎng)站收錄、面包屑導航、自適應網(wǎng)站、用戶體驗

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設