What is the difference between forward and sendRedirect?A forward is server side redirect while sendRedirect is client side redirect. When a forward request is invoked, the request is sent to another resource on the server. The client is not informed that a different resource is going to process the request. This process occurs completely within the web container and then returns to the calling method. When a sendRedirect method is invoked, it causes the web container to return to the browser indicating that a new URL should be requested. As a result any object that is stored as a request attribute before the redirect occurs will be lost. Due to this extra round trip, a sendRedirect is slower than forward.
What's the difference between forward and sendRedirect?The basic difference between these two is that, sendRedirect() is a header that always sent back to the client. This header has the resources such as page or servlet which is to be redirected. This header can be used by the browser to make another fresh request. In case of forward() method call, the resources from the server which forward() call was made, can only be requested for. The forward() can just routes the request to the new resources. This route is made by servlet engine. No headers are sent to the browser.
|