欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Java中Request請(qǐng)求轉(zhuǎn)發(fā)詳解

 更新時(shí)間:2020年07月12日 14:20:40   作者:持續(xù)更新,2天一篇  
這篇文章主要介紹了Java中Request請(qǐng)求轉(zhuǎn)發(fā)詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

直接來,RequestDemo5代碼,get請(qǐng)求和post請(qǐng)求都請(qǐng)求轉(zhuǎn)發(fā)了,轉(zhuǎn)發(fā)到RequestDemo6請(qǐng)求

 RequestDemo5代碼

package com.lingaolu.request;
 
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
 
/**
 * @author 林高祿
 * @create 2020-07-07-12:06
 */
@WebServlet("/requestDemo5")
public class RequestDemo5 extends HttpServlet {
 
 @Override
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 System.out.println("requestDemo5進(jìn)來了......post");
 RequestDispatcher requestDispatcher = request.getRequestDispatcher("/requestDemo6");
 requestDispatcher.forward(request,response);
 }
 
 @Override
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 System.out.println("requestDemo5進(jìn)來了......get");
 RequestDispatcher requestDispatcher = request.getRequestDispatcher("/requestDemo6");
 requestDispatcher.forward(request,response);
 
 }
}

RequestDemo6代碼

package com.lingaolu.request;
 
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
 
/**
 * @author 林高祿
 * @create 2020-07-07-12:06
 */
@WebServlet("/requestDemo6")
public class RequestDemo6 extends HttpServlet {
 
 @Override
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 System.out.println("requestDemo6進(jìn)來了......post");
 }
 
 @Override
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 System.out.println("requestDemo6進(jìn)來了......get");
 }
}

瀏覽器訪問/requestDemo5接口

控制臺(tái)輸出

從以上結(jié)果可以看出

請(qǐng)求過后我們的瀏覽器地址還是http://localhost:8080/myRequest/requestDemo5

從瀏覽器的F12調(diào)試頁面可以看出,轉(zhuǎn)發(fā)只是一次請(qǐng)求,只有/requestDemo5請(qǐng)求,說明,可共享數(shù)據(jù)Request共享數(shù)據(jù)

我們用Postman進(jìn)行post請(qǐng)求一下

后臺(tái)輸出:

可見,get請(qǐng)求的轉(zhuǎn)發(fā)會(huì)轉(zhuǎn)發(fā)到get請(qǐng)求,post請(qǐng)求的轉(zhuǎn)發(fā),會(huì)轉(zhuǎn)發(fā)到post請(qǐng)求

我們改一下RequestDemo5的代碼,轉(zhuǎn)發(fā)到百度

package com.lingaolu.request;
 
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
 
/**
 * @author 林高祿
 * @create 2020-07-07-12:06
 */
@WebServlet("/requestDemo5")
public class RequestDemo5 extends HttpServlet {
 
 @Override
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 System.out.println("requestDemo5進(jìn)來了......post");
 RequestDispatcher requestDispatcher = request.getRequestDispatcher("/requestDemo6");
 requestDispatcher.forward(request,response);
 }
 
 @Override
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 System.out.println("requestDemo5進(jìn)來了......get");
 RequestDispatcher requestDispatcher = request.getRequestDispatcher("https://www.baidu.com/");
 requestDispatcher.forward(request,response);
 
 }
}

瀏覽器請(qǐng)求

 后臺(tái)輸出:

從后臺(tái)輸出看出,requestDemo5請(qǐng)求進(jìn)來了,從瀏覽器看出,轉(zhuǎn)發(fā)失敗了,而且從實(shí)際轉(zhuǎn)發(fā)的路徑上看,因?yàn)樘摂M路徑,所以請(qǐng)求轉(zhuǎn)發(fā)只能轉(zhuǎn)發(fā)到當(dāng)前服務(wù)器內(nèi)部的資源

請(qǐng)求轉(zhuǎn)發(fā)的特點(diǎn)總結(jié):(與之對(duì)應(yīng)的------重定向的詳情與特點(diǎn)

  • 瀏覽器地址欄路徑不發(fā)生變化
  • 轉(zhuǎn)發(fā)只是一次請(qǐng)求,可共享數(shù)據(jù)Request共享數(shù)據(jù)
  • 哪種請(qǐng)求方式只能轉(zhuǎn)發(fā)到那種請(qǐng)求方式
  • 請(qǐng)求轉(zhuǎn)發(fā)只能轉(zhuǎn)發(fā)到當(dāng)前服務(wù)器內(nèi)部的資源

到此這篇關(guān)于Java中Request請(qǐng)求轉(zhuǎn)發(fā)詳解的文章就介紹到這了,更多相關(guān)Java Request請(qǐng)求轉(zhuǎn)發(fā)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 通過Spring Boot + Mybatis + Redis快速搭建現(xiàn)代化Web項(xiàng)目

    通過Spring Boot + Mybatis + Redis快速搭建現(xiàn)代化Web項(xiàng)目

    本篇文章介紹了如何通過Spring Boot、Mybatis以及Redis快速搭建一個(gè)現(xiàn)代化的Web項(xiàng)目,并且同時(shí)介紹了如何在Spring Boot下優(yōu)雅地書寫單元測試來保證我們的代碼質(zhì)量。具體內(nèi)容詳情大家通過本文學(xué)習(xí)下吧
    2017-12-12
  • 面向切面的Spring通過切點(diǎn)來選擇連接點(diǎn)實(shí)例詳解

    面向切面的Spring通過切點(diǎn)來選擇連接點(diǎn)實(shí)例詳解

    這篇文章主要為大家介紹了面向切面的Spring通過切點(diǎn)來選擇連接點(diǎn)實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-10-10
  • java實(shí)現(xiàn)讀取txt文件中的內(nèi)容

    java實(shí)現(xiàn)讀取txt文件中的內(nèi)容

    本文通過一個(gè)具體的例子向大家展示了如何使用java實(shí)現(xiàn)讀取TXT文件里的內(nèi)容的方法以及思路,有需要的小伙伴可以參考下
    2016-03-03
  • jconsole使用介紹(圖文)

    jconsole使用介紹(圖文)

    大家在學(xué)習(xí)java的時(shí)候,難免會(huì)對(duì)jvm進(jìn)行一些深入的了解。推薦大家使用jdk下面的jconsole.exe來輔助理解jvm的一些概念
    2015-12-12
  • Java中隊(duì)列Queue和Deque的區(qū)別與代碼實(shí)例

    Java中隊(duì)列Queue和Deque的區(qū)別與代碼實(shí)例

    學(xué)過數(shù)據(jù)結(jié)構(gòu)的,一定對(duì)隊(duì)列不陌生,java也實(shí)現(xiàn)了隊(duì)列,下面這篇文章主要給大家介紹了關(guān)于Java中隊(duì)列Queue和Deque區(qū)別的相關(guān)資料,需要的朋友可以參考下
    2021-08-08
  • 最新評(píng)論