Ali side - the difference between redirection and request forwarding in HTTP?

The season of gold, silver and silver is coming soon . It is a good time to look for a job. You must seize the opportunity to find your favorite high-paying job. If you are looking for a job, you can’t do without an interview. From now on, let’s brush up on the interview questions and find out what’s missing! ! !

4d4cae98b348412db70f24c76ebe19c8.gif


content

⭐What is the difference between TCP and UDP?

⭐ What is the HTTP protocol?

⭐TCP three-way handshake

⭐ Difference between redirection and request forwarding in HTTP?

⭐ Difference between Get and Post?

⭐What is the difference between cookies and sessions?


 

f1ed79363538443484ca8bf943c020d0.gif


⭐What is the difference between TCP and UDP?

TCP (Transmission Control Protocol) is a connection-oriented (connection-oriented), reliable, IP-based transport layer protocol.

UDP is the abbreviation of User Datagram Protocol. The Chinese name is User Datagram Protocol. It is a transport layer protocol in the OSI reference model. It is a connectionless transport layer protocol that provides transaction-oriented simple and unreliable information transmission services. 

Both TCP and UDP are protocols from the transport layer. The transport layer is located between the application layer and the network layer and is responsible for communication between processes located in different hosts.


 1.TCP is based on connection UDP has no connection
 2.TCP requires more system resources, UDP less 
 3.TCP guarantees data correctness, UDP may lose packets 
 4.TCP guarantees data order, UDP does not guarantee 


0c0c1c8047a7415db8d14ce02c59ae76.png


⭐ What is the HTTP protocol?

The format specification for data transmission between the client and the server, the format is referred to as "Hypertext Transfer Protocol".

It is a stateless, application layer protocol based on request and response mode, based on TCP connection method

33af0cd4316f4074a5a80f76053829a3.png


⭐TCP three-way handshake

6aab607e78f04a83b7b5e3fb8ba3c381.png


Why three handshakes?

The purpose of the three-way handshake is to establish a reliable communication channel. When it comes to communication, it is simply the sending and receiving of data, and the main purpose of the three-way handshake is to confirm that the sending and receiving of themselves and the other party is normal.

SYN: Synchronize Sequence Numbers. It is the handshake signal used by TCP/IP to establish a connection.

First handshake: The client sends a SYN to the server. The client sends a network packet, and the server receives it. The server concludes that the sending ability of the client and the receiving ability of the server are normal.
Second handshake: After the server receives the SYN message, it will respond with a SYN+ACK message. The server sends the packet and the client receives it. The client concludes that the server's receiving and sending capabilities and the client's receiving and sending capabilities are normal. However, at this time, the server cannot confirm whether the receiving capability of the client is normal.
The third handshake; after the client receives the SYN+ACK message, it responds with an ACK message. The client sends the package and the server receives it. The server concludes that the client's receiving and sending capabilities and its own receiving and sending capabilities are normal.
Through the three-way handshake, both parties confirm that the receiving and sending capabilities of the other party are normal.

7315d69d674a4d88a3aa9231ed396394.png


⭐ Difference between redirection and request forwarding in HTTP?

Implement 
forwarding : use the getRequestDispatcher() method of the request to get the ReuqestDispatcher object, and call the forward() method

request.getRequestDispatcher("other.jsp").forward(request, response);

Redirection : call the sendRedirect() method of the response

response.sendRedirect("other.jsp");

1> Redirect 2 requests, request to forward 1 request

2> The redirect address bar will change, and the request forwarding address bar will remain unchanged

3> Redirection is browser jump, request forwarding is server jump

4> Redirect can jump to any URL, request forwarding can only jump to the current project

d388cbea31a84bf5854d070368a5cd50.png


⭐ Difference between Get and Post?

1. Get is insecure because during transmission, the data is placed in the requested URL; all operations of Post are invisible to the user.  

2. The amount of data transmitted by Get is small, and the size of the transmitted data generally does not exceed 2k-4k (depending on the browser, the limit is different, but the difference is not large. This is mainly due to the limitation of the URL length; the amount of data transmitted by Post is large, It is generally defaulted to unlimited.       

3. Get restricts the value of the data set of the Form form to be ASCII characters; while Post supports the entire ISO10646 character set.                     

4. The execution efficiency of Get is better than that of Post. Get is the default method for form submission. 

be3d896f37d544edae82759c6452c980.png


⭐What is the difference between cookies and sessions?

1. Different storage locations

The data information of the cookie is stored on the client browser.

Session data information is stored on the server.  

2. Different storage capacity

The data saved by a single cookie is <= 4KB, and a site can save up to 20 cookies.

There is no upper limit for the session, but for the performance of the server side, do not store too many things in the session, and set the session deletion mechanism.

3. Different storage methods

Only ASCII strings can be stored in cookies, and they need to be stored as Unicode characters or binary data by encoding.

Any type of data can be stored in the session, including but not limited to string, integer, list, map, etc.

4. Different privacy policies

The cookie is visible to the client, and people with ulterior motives can analyze the cookie stored locally and perform cookie deception, so it is not safe.

Sessions are stored on the server, and there is no risk of sensitive information leakage.

5. The  validity period is different

Developers can set the properties of cookies to achieve the effect of making cookies effective for a long time.

The session depends on the cookie named JSESSIONID, and the expiration time of the cookie JSESSIONID is -1 by default. Just closing the window will invalidate the session, so the session cannot achieve long-term effective effects.

6. Different server pressure

The cookie is stored on the client side and does not occupy server resources. For sites with a lot of concurrent users, cookies are a good choice.

The session is kept on the server side, and each user will generate a session. If there are a lot of users accessing concurrently, a lot of sessions will be generated, consuming a lot of memory.


eee79ebe89334a718b308146e4861067.gif

b5e9aea57af942b9883c7992fdc12c35.gif


 

Guess you like

Origin blog.csdn.net/weixin_42306958/article/details/123079999