Servletresponse request redirection

Source: Internet
Author: User

Package response;
/*
* Redirection features:
* 1. the browser sends two requests to the server, which means there are two requests \ response
* 2. the address bar of the browser changes with the redirection technology.
*
* Redirection technology is usually used when users log on to and display the shopping cart.
*
*
**/
/*
* Response Details
* 1. response. getoutputstream conflicts with getwriter.
*
**/
Import java. Io. ioexception;
Import javax. servlet. servletexception;
Import javax. servlet. http. httpservlet;
Import javax. servlet. http. httpservletrequest;
Import javax. servlet. http. httpservletresponse;
// Implement request redirection (you ask me to borrow money, I said I did not, let you find someone else)
// Use environment: the user logs on. After logging on, the user jumps to other pages for shopping;
// Redirection, the address bar will change
// Redirection is not needed. It is best not to use it because it will send two requests to the server, adding the server burden
Public class responsedemo7 extends httpservlet {
Protected void doget (httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {
/// 1, method 1
//// Send the status code, telling you to find someone else
// Response. setstatus (302 );
//// Redirect. I want you to go to the index. jsp page.
// Response. setheader ("location", "/requestandresponse/index. jsp ");

// 2, method 2
Response. sendredirect ("/requestandresponse/index. jsp ");
}
Protected void dopost (httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {
Doget (request, 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.