Difference between forward and sendRedirect

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.
Difference between jsp and servlet life cycles
JSP and Servlet - In JSP's life cycle, after a jsp is translated into a servlet, it behaves in the same way as a servlet...
JSP Scripting Elements - Explain JSP Scripting Elements
JSP Scripting Elements - There are three forms of JSP scripting elements that let you insert Java code into the servlet...
Difference between JSP include directive and JSP include action.
JSP include directive - When a JSP include directive is used, the included file's code is added into the added JSP page at page translation time...
Post your comment