Difference between forward and redirect
1. the URL in the browser address bar remains unchanged after the forward redirection is used.
The address bar of redirect will be changed to the new address after the jump.
2. Forward redirects can only be other Web components of the same web application.
Redirect can be any URL.
3. when a client (browser) requests a JSP that uses forward for redirection, the client (browser) only interacts with the server once. The redirection of forward is implemented by the server, and the customer does not know that there is a redirection; when a client (browser) requests a JSP that uses redirect for redirection, redirect
The browser will first send a response to the browser, then the browser receives the response and then sends a requeset to the server, and then the server sends a new response to the browser. The client (browser) interacts with the server twice.
4. when you use redirect to jump to a page, due to (3) reasons, when the client requests the server, the parameters following the URL are no longer displayed during the jump. Therefore, these parameters cannot be obtained on the final JSP page, but you can use response. setattribute (
"Name", name) to the next page.
JSP
Example of Using forward and redirect
<%
String forward = "JSP/forward. jsp ";
String redirect = "JSP/redirect. jsp ";
Response. sendredirect (redirect); // use
Redirect through redirect
// Request. getrequestdispatcher (forward). Forward (request,
Response); // use forward to redirect
%>