The difference between Forward and Redirect is that when a user sends an HTTP request to a server, the request may be processed by multiple information resources before it is returned to the user. Each information resource forwards the request to the server using the request forwarding mechanism, but the user does not notice the request forwarding. What is the difference between Forward and Redirect forwarding? This article will be shared with you by the Good Programmer Java tutorial.

Java3

I. From the definition:

Forward is when the server requests the resource, accesses the URL of the destination address, reads the response from that URL, and sends it back to the browser. The browser has no idea where the content sent by the server came from, so its address bar remains the same.

Redirect is a server that logically sends a status code telling the browser to redirect to that address. So the address bar shows the new URL. Redirect means the client sends two requests to the server and receives two responses.

Ii. From the perspective of principle:

Forward (direct Forward mode) is more used, generally speaking, request Forward refers to the direct Forward mode. Most Web applications will have a controller. The controller controls which information resource the request should be forwarded to. The request is then processed by these information resources and may be forwarded to another information resource to be returned to the user. This process is the classic MVC pattern.

Redirect, sometimes called redirection, is used to avoid unwanted visits from users. For example, if a user accesses a background resource without logging in, the Servlet can redirect the HTTP request to the login page for the user to log in and access it later.

Iii. From the perspective of working process:

Forword procedure: the client browser sends an HTTP request –> the Web server accepts the request –> invokes an internal method to handle the request and forward the action inside the container –> sends the target resource to the client.

Redirect process: The client browser sends an HTTP request — the Web server receives the request and sends a 302 status code response with a new location to the client browser — the client browser finds a 302 response and automatically sends a new HTTP request. The request URL is the new location address -> the server finds the resource based on this request and sends it to the client.

Four, from the use of the place

Forword is generally used when users log in and forward to the corresponding module according to the role.

Redirect Normally, users return to the home page or redirect to other websites when they log out.

V. From the perspective of efficiency:

Forword is efficient and Redirect is inefficient.

The difference between Forward and Redirect is the difference between Forward and Redirect.