Get the App
SLTechnology News&Howtos  ›  Development  › 

How does Java Webresponse complete the redirection implementation?

Shulou Source: shulou.com Published: 2022-06-03 05:07:38 09月22日 Update

Today, I will talk to you about how Java Webresponse completes the process of redirecting. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

one。 Understanding of redirection

> the client sends a request to the server, and the server returns 302 and brings an address to the browser and asks the browser to request this address. This process is redirection.

For example, there are three people who ask B to do something for A, respectively. B is powerless. B gives A the address of C and asks A to ask C to do it. To put it simply: ask for help.

two。 Considerations for redirection

When the server returns 302 to the browser, it also brings an address, which is sent in the form of a response header, and the name of the header must be Location

During the redirection, the browser sent two requests

three。 Example of flowchart

four。 Code example:

Package cn.xxx.Servlet;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class BServlet extends HttpServlet {protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {/ / set location response header response.setHeader ("Location", "/ Demo01/CServlet"); response.setStatus (302); / / send status code}}

Package cn.xxx.Servlet;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class CServlet extends HttpServlet {protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {System.out.println ("CServlet");}}

After reading the above, do you have any further understanding of how Java Webresponse completes the redirection implementation process? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: Address process browser browsing content server service that is example incompetent powerless two personal event code name client client form more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Information Redmi Microsoft MySQL