Explain spring MVC request forwarding and redirection
Comparison between request redirection and request forwarding, httpservletresponse Sendredirect method and requestdispatcher The forward method allows the browser to obtain the resource pointed to by another URL, but the internal operation mechanism of the two methods is very different.
1.RequestDispatcher. The forward method can only forward requests to components in the same web application, httpservletresponse Sendredirect can redirect not only to other resources of the current application, but also to resources of other applications on the same site, or even to resources of other sites using absolute URLs. For sendredirect, if the delivered URL starts with "/", it is the root directory relative to the whole web site; For forward, if the URL passed starts with "/", it is the root directory relative to the current web application.
2. Sendredirect's response to the browser is to reissue the access request to another URL. Forward forwards the request to another resource inside the server. The browser only knows that the request has been sent and the response result has been obtained
3. The caller and callee of forward share the same request object and response object. They belong to the same access request and response process; The caller and callee of sendredirect use their own request and response objects, which belong to two independent access request and response processes
Request redirection starts with redirect: and request forwarding starts with forward:;
Examples are as follows:
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.