Request redirection refers to a request redirection when a Web Resource notifies the client to access another Web Resource after receiving a request from the client. 302 status code and Location header to achieve redirection.
The most common application scenario of request redirection is user logon. The following sample code redirects from another page to the user logon page:
1 package COM. yyz. response; 2 3 Import Java. io. ioexception; 4 Import javax. servlet. servletexception; 5 import javax. servlet. HTTP. httpservlet; 6 Import javax. servlet. HTTP. httpservletrequest; 7 Import javax. servlet. HTTP. httpservletresponse; 8 public class responsedemo extends httpservlet {9 10 public void doget (httpservletrequest request, httpservletresponse response) 11 throws servletexception, ioexception {12 response. setheader ("location", "/day06/register.html"); 13 response. setstatus (302); 14 // the above two statements are equivalent to the following code: 15 // response. sendredirect ("/day06/register.html"); 16} 17 Public void dopost (httpservletrequest request, httpservletresponse response) 18 throws servletexception, ioexception {19 doget (request, response ); 20} 21}
Two notable features of request redirection: 1. Two requests are sent to the server. 2. the address bar is changed. Because an important principle for server optimization is to reduce the number of requests sent, less request redirection is required.
Response Summary (5)-request redirection through response