Difference between forward and sendRedirect

forward and sendRedirect both method calls indicate that server is going to display a page other than the one requested. The implicit meaning of these two method calls is that the requested page/resource is going to forward or re-direct the request to another page/resource on the server due to various reasons. Here is the difference between forward and sendRedirect method calls:



1. It is a server side redirect It is a client side redirect
2. When invoked, the request is sent to another resource on the server. Client is not informed that the request is going to be processed by a different resource. When invoked, the call is returned back to the browser. Client is informed that a new resource/URL should be requested. Client then select the new URL and browser then issues a completely new request.
3. Both resources must be part of the same context. Both resource may be part of the same or different context.
4. Request attributes are retained Request attributes are lost
5. Faster as the whole process gets completed on server and does not involve any extra round trip. Slower because of the extra round trip request.
6. RequestDispatcher.forward HttpServletResponse.sendRedirect

Thus whether to use forward of sendRedirect, solely depends on the application’s requirement.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">