当前位置:网站首页>What is the difference between request forwarding and request redirection?
What is the difference between request forwarding and request redirection?
2022-07-26 00:41:00 【Xianling Pavilion】
stay Java in , There are two ways to realize jump : Request forwarding and request redirection , But the two are completely different , So let's play it today .
The main difference between request forwarding and request redirection , Contains the following 5 spot :
1. Different definitions
2. Jump party is different
3. Data sharing is different
4. Final URL Address different
5. The code implementation is different
Next , Let's look at them one by one .
1. Different definitions
Request forwarding (Forward): Occurs inside the server program , When the server receives a request from a client , Will first request , Forward to the destination address , Then forward the result returned by the target address to the client . And the client has no perception of all this , This is like comparison. , Zhang San ( client ) Look for Li Si ( Server side ) To borrow money , And Li Si has no money , So Li Si went to Wang Wu to borrow money , And lent the money to Zhang San , During the whole process, Zhang San only borrowed money once , The rest of the work was done by Li Si , This is request forwarding .
** request redirections (Redirect): Request redirection refers to after the server receives the request from the client , Will return a temporary response header to the client , This temporary response header records , The client needs to send the request again ( Redirect ) Of URL Address , After the client receives the address , The request will be sent to the new address , This is request redirection .** It's like Zhang San ( client ) Look for Li Si ( Server side ) To borrow money , Li Si has no money , So Li Si told Zhang San ,“ I have no money , Go to Wang Wu to borrow “, So Zhang San went to Wang Wu's house to borrow money , This is request redirection .
2. The requestor is different
From the above definition of request forwarding and request redirection , We can see that : Request forwarding is a server-side behavior , The server sends the request instead of the client , And return the result to the client ; And requesting redirection is the behavior of the client , Their interaction process , As shown in the figure below :
3. Data sharing is different
Request forwarding is implemented on the server , So in the whole execution process , client ( Browser side ) Just send the request once , Therefore, the same one is used in the whole interaction process Request Request object and a Response The response object , So the whole request process , The requested and returned data are shared ; The request redirection client sends two completely different requests , So the data in the two requests are different .
4. Final URL Address different
Request forwarding is the server-side request , And then return the result to the client , So the whole request process URL The address is the same ; The request for redirection is for the server to tell the client ,“ You go to another place to visit ”, So the browser will send the request again , So the client end up showing URL Also the address of the final jump , Instead of the address you just requested , therefore URL The address has changed .
5. The code implementation is different
stay SpringBoot in , The implementation code of request forwarding is as follows :
@RequestMapping("/fw")
public void forward(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.getRequestDispatcher("/index.html").forward(request, response);
}
Copy code
The implementation code of request redirection is as follows :
@RequestMapping("/rt")
public void redirect(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.sendRedirect("/index.html");
}
Copy code
summary
Request forwarding and request redirection follow “ The less words , The bigger the matter is ” Principles ,“ Request forwarding ” There are fewer words , It needs to perform jump on behalf of the client ; and “ request redirections ” A lot of words , It does nothing , Just tell the client “ You visit somewhere else ” That's it , This is the key to understand these two concepts . Their differences are mainly reflected in 5 A little bit : Different definitions 、 The requestor is different 、 Data sharing is different 、 Final URL Address different 、 The code implementation is different .
The source code attachment has been packaged and uploaded to Baidu cloud , You can download it yourself ~
link : https://pan.baidu.com/s/14G-bpVthImHD4eosZUNSFA?pwd=yu27
Extraction code : yu27
Baidu cloud link is unstable , It may fail at any time , Let's keep it tight .
If Baidu cloud link fails , Please leave me a message , When I see it, I will update it in time ~
Open source address
Code cloud address :
http://github.crmeb.net/u/defu
Github Address :
http://github.crmeb.net/u/defu
link :https://juejin.cn/post/7121513633237958670
边栏推荐
- 向左旋转k个字符串(细节)
- Applet page generation link sent by SMS
- 开发还没联调,任务就要上线
- hcia综合实验
- [oops framework] interface management
- Preparation of bovine erythrocyte superoxide dismutase sod/ folic acid coupled 2-ME albumin nanoparticles modified by bovine serum albumin
- The way of understanding JS: what is prototype chain
- C#从入门到精通(三)
- SereTOD2022 Track1代码剖析-面向半监督和强化学习的任务型对话系统挑战赛
- SQL server failed to send mail, prompting that the recipient must be specified
猜你喜欢

Hcip day 13

Research on the influence of opinion leaders based on network analysis and text mining

Tid-mop: a comprehensive framework for security management and control under the scenario of data exchange

8 tips to adjust database performance optimization, yyds

Verilog语法基础HDL Bits训练 06

Getting started with D3D calculation shaders
![[redis] ② redis general command; Why is redis so fast?; Redis data type](/img/72/aaa90d5411b8b20b15a7f87b98bd27.png)
[redis] ② redis general command; Why is redis so fast?; Redis data type

【无标题】如何实现可插拔配置?

Hoops exchange helps hybrid computational fluid dynamics software build 3D format import and read function | customer case

Applet page generation link sent by SMS
随机推荐
Redis (VIII) - redis enterprises' actual coupons spike
【计算一个字符串和另一个字符串相等的次数】
Shardingsphere data slicing
JVM Tri Color marking and read-write barrier
为了拿捏 Redis 数据结构,我画了 40 张图(完整版)
[IJCAI 2022] parameter efficient large model sparse training method, which greatly reduces the resources required for sparse training
Are you still counting the time complexity?
Quick start sequence table chain table
Tid-mop: a comprehensive framework for security management and control under the scenario of data exchange
GOM和GEE引擎黑屏不显示界面,装备地图怪物的解决方法
[oops framework] random number generation management
力扣记录:剑指offer(2)——JZ13-22
LCA three postures (multiplication, tarjan+ joint search set, tree chain dissection)
Rotate K strings to the left (details)
JVM 三色标记法与读写屏障
Azure synapse analytics Performance Optimization Guide (1) -- optimize performance using ordered aggregate column storage indexes
HOOPS Exchange助力混合计算流体动力学软件搭建3D格式导入读取功能 | 客户案例
Prefix XOR sum, XOR difference array
Research on the integrated data quality management system and technical framework under the scenario of data circulation and transaction
JMeter/IDEA中引用jar包json-path.jar的坎坷之路