General Method Response.setstatus (302); Response.setheader ("Location", "/20160314/index.jsp");
Good method Response.sendredirect ("/20160314/index.jsp");
The request redirection operation can be implemented by setting the status code to 302 with response and setting the response header location to the address to redirect to. To facilitate the request redirection operation, Response provides the Response.sendredirec ("....") and implements the request redirection.
In most cases, the effect of request redirection and forwarding is similar, and we recommend using forwarding to reduce access to the server. In some cases, it is necessary to use forwarding, often in order to change the address in the browser address bar (such as the successful login to the home page), and change the refresh operation (such as adding items to the shopping cart after the move to the shopping cart page operation)
Response Generating Response considerations
The two methods of Getoutputstream and getwriter are mutually exclusive, and any one of them is called, and no other method can be called.
The data written to the Servletoutputstream or PrintWriter object by the servlet program is fetched by the servlet engine from the response, and the servlet engine treats the data as the body of the response message. It is then combined with the response status line and each response header to output to the client. After the Serlvet service method finishes, the Servlet engine checks whether the output stream object returned by the Getwriter or Getoutputstream method has already called the Close method, and if not, The servlet engine Tomcat will call the Close method to close the output stream object.
20160322 Javaweb Learning Notes--response redirect