当前位置:网站首页>Detailed explanation of redirection and request forwarding
Detailed explanation of redirection and request forwarding
2022-04-23 15:18:00 【Spruce cabin】
Redirection and request forwarding details
Abstract : This note focuses on the difference between redirection and request forwarding 、 Their characteristics .
1. Request forwarding
Request forwarding itself is a server behavior , Its essence is that after the client request reaches the server , The server forwards the request information and saves the object to be forwarded , At this point, if we use a browser , You'll find... Above the browser URL The path in the path bar is unchanged . This is an internal behavior of the server , It's a servlet Forward a request to another server inside the server servlet act , This jump can only occur inside the server , In other words, the request can only be forwarded to a resource located inside the server , It cannot be forwarded to the outside , This is related to the storage method of request information inside the server . Next, we use diagrams to describe the process of request forwarding :
We send a request to the server in the client , First you need to use URL Conduct a path construction , After the connection is established, we can send our request , This is a computer network related knowledge , Before we communicate online , First, a connection will be established in some way , Then carry out data transmission , The main body in data transmission is the request we send , There is actually no standardized storage format for our requests outside the server , They are electrical signals or optical signals on the network cable , At this time, they are in the physical layer , The data of the physical layer cannot be directly recognized by the application of the application layer , However, they can be received by the server specified by the link layer protocol , After being received by the server , Naturally, there is a need for driver and operating system processing , Then send it to Tomcat 了 , After receiving the message Tomcat These request information will be converted into HttpServlet The format is saved in its own process , And send according to its request target , As shown above, it was sent to ServletA,ServletA It's a Servlet, stay Servlet in , The request is converted to HttpServletRequest The format of , Therefore, there is also a format conversion , and ServletA It is found that there is an operation requesting forwarding , Then execute the relevant code ,Tomcat The request object will be formatted , First convert to HttpServlet The format of , Then forward it to another Servlet. In the process ,HttpRequest Cannot be transformed into Request, But only in HttpServletRequest And HttpRequest Transition between two states , because Tomcat It is not provided to change the internal format back to Request Format function , therefore , Request forwarding cannot jump to external resources , And it is a request from the client to the server .
Request forwarding is a server-side behavior , It's not about users , Completely implemented by the server .
2. Redirect
Redirection and request forwarding can realize the function of page Jump , But when we learn from them, we stop here , At best, I know that redirection will make URL Change , The request for resources can no longer use the relative path of the previous page , The request can only be made again with the current page as the starting point . Why is this , Let's look at the principle of focusing on orientation in a graphical way :
In redirection , Another object is used ,Response object , This object is specially used to return information to the client , When using redirection ,Servlet No more jumping down , But use HttpServletResponse Object returned to the client , It will ServletB The address of is returned to the client , Then let the client access the address again , So the client sends another request , This request is made directly to ServletB Request . This explains why when we use redirection ,URL It will change , So we resend the request , Redirection is a secondary request , It's different from request forwarding , meanwhile ,ServletA The returned address is not necessarily the internal resource address of the server , You can also make an off-site address , In this way, the jump of resources outside the station can be realized .
Request forwarding is not a simple server-side behavior , It's a server-side guided client-side behavior .
3. summary
When using the browser to observe, we can find that the request forwarding is only one request , Redirection has a second request , Both have advantages and disadvantages , Redirection takes longer , And need to relocate resources , The request forwarding time is slightly shorter , But you can only access the resources in the station , Usually, we don't use redirection when writing website page Jump , This is to avoid the trouble caused by relocating resources , Of course, the way we use absolute positioning for resource access is not an obstacle , It can only be said that the choice is made according to the specific situation .
版权声明
本文为[Spruce cabin]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231508540995.html
边栏推荐
- Share 20 tips for ES6 that should not be missed
- Leetcode162 - find peak - dichotomy - array
- 小红书 timestamp2 (2022/04/22)
- Async void caused the program to crash
- 22年了你还不知道文件包含漏洞?
- 让阿里P8都为之着迷的分布式核心原理解析到底讲了啥?看完我惊了
- Adobe Illustrator menu in Chinese and English
- js——實現點擊複制功能
- Sword finger offer (2) -- for Huawei
- MySQL sync could not find first log file name in binary log index file error
猜你喜欢
Kubernetes详解(九)——资源配置清单创建Pod实战
About UDP receiving ICMP port unreachable
Detailed explanation of kubernetes (XI) -- label and label selector
My raspberry PI zero 2W tossing notes record some problems encountered and solutions
API gateway / API gateway (III) - use of Kong - current limiting rate limiting (redis)
For 22 years, you didn't know the file contained vulnerabilities?
Nuxt project: Global get process Env information
Set onedrive or Google drive as a drawing bed in upic for free
Tun equipment principle
让阿里P8都为之着迷的分布式核心原理解析到底讲了啥?看完我惊了
随机推荐
Detailed explanation of MySQL connection query
Three uses of kprobe
What is the effect of Zhongfu Jinshi wealth class 29800? Walk with professional investors to make investment easier
Five data types of redis
Practice of unified storage technology of oppo data Lake
For 22 years, you didn't know the file contained vulnerabilities?
封面和标题中的关键词怎么写?做自媒体为什么视频没有播放量
Borui data and F5 jointly build the full data chain DNA of financial technology from code to user
Byte interview programming question: the minimum number of K
Leetcode165 compare version number double pointer string
LeetCode151-颠倒字符串中的单词-字符串-模拟
Detailed explanation of C language knowledge points -- first understanding of C language [1] - vs2022 debugging skills and code practice [1]
redis-shake 使用中遇到的错误整理
Async void caused the program to crash
22年了你还不知道文件包含漏洞?
Difference between like and regexp
js——實現點擊複制功能
Comment eolink facilite le télétravail
Set onedrive or Google drive as a drawing bed in upic for free
JS - implémenter la fonction de copie par clic