Forward and redirect, forwardredirectForward and redirect
1. Use the forward method
Request. getRequestDispatcher (path). forward (request. response );First, let's take a look at the getRequestDispatcher method. The path must be a relative
Response in JSP. sendredirect () and request. getrequestdispatcher (). both the forward (request, response) objects can redirect pages, but there is a big difference between the two objects. In terms of separation, there are the following
This time, you can select your favorite color on the homepage to go to the corresponding page.
Select green to go to the green page:
Select red to go to the Red Page:
Okay. Here we will see four pages:
Select the color in index. jsp and click the
I. Article 1Both the Httpservletresponse.sendredirect and Requestdispatcher.forward methods can be implemented to obtain the appropriate URL resources.Sendredirect implements request redirection, forward implements request forwarding.The processing
1. servlet redirection forward and redirect:There are two ways to use servlet redirection, one is forward and the other is redirect. Forward is a server internal redirect, and the client does not know where the server redirects your current request,
Sendredirect & forwardKeywords: sendredirect & FO1. When sendredirect is enabled, the server first responds to the client's status code (usually 302), telling the client to resend the request to the URL specified in the location header (which can be
Response in JSP. sendredirect () and request. getrequestdispatcher (). both of the Forward (request, response) objects can redirect pages, but there is a big difference between the two objects. In terms of the split, there are the following points: ①
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.