Response Summary (5)-request redirection through response

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.