[Business Functions Chapter 95] Redirection and forwarding in the web

Return value of web interface:

Forward: return “/reg” Jump to the html page of reg

Redirect return "redirect:/login.html" Redirect and re-initiate the request path is login.html. For example, the request address of the interface @requestmap("/login.html") we wrote, re-request

  • Purpose:

Forwarding: Forwarding is a page jump performed on the server side. Its main purpose is to pass the request to another resource (usually another Servlet or JSP) in order to generate a response during the same request.

Redirect: A redirect is a page jump in the client browser. Its main purpose is to tell the browser to send the request to a new URL address.

  • Location:

Forwarding: Forwarding is an internal operation of the server. The browser does not know that it has been forwarded, and the URL address remains unchanged.

Redirect: A redirect is a response sent by the server to the browser, and the browser initiates a new request based on the new URL address.

  • HTTP status code:

Forwarding: Forwarding does not change the HTTP status code. The HTTP status code of the original request remains unchanged.

Redirects: Redirects usually return an HTTP status code, such as 302 Found or 301 Moved Permanently, to instruct the browser to perform a jump.

  • Data transfer:

Forwarding: Forwarding can pass data in the same request. The original request and forwarding target can share request parameters and properties.

Redirection: Redirection does not share data. Any data needs to be passed via URL parameters or session.

  • performance:

Forwarding: Forwarding is usually faster than redirecting because it is done internally on the server and requires no additional network requests.

Redirects: Redirects may cause additional network round-trips and therefore poor performance.

  • use:

Forwarding: Suitable for page navigation between different components within the same application, keeping the URL unchanged and sharing data. Redirect: Suitable for cross-domain page jumps, or navigation between different web applications, or after processing a form submission to avoid repeated submission of the form when the user refreshes.

Guess you like

Origin blog.csdn.net/studyday1/article/details/132643704