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 );
}
}