What is difference between HTTP Redirect and Forward

Carvia Tech | August 05, 2019 | 2 min read | 28 views


Http Forward

  1. Control is forwarded to the resource available within the server from where the call is made, the transfer of control is made internally by the container, where client is completely unaware that a forward is happening.

  2. When forward is done, the original request and response objects are transferred along with the additional parameters if needed.

  3. Forward can’t transfer control to some other domain.

  4. Original URL at the client side remains intact, refreshing the page will cause the whole step to repeat again.

  5. Session object is not lost in forward or redirect.

Http Redirect

  1. A redirect is a two step process where web application instructs the browser client to fetch the fetch the second URL which differs from the original.

  2. Server sends Http Status Code of 301 to the client, and then client follows the instructions.

  3. If someone reloads the page on browser, then original request will not be repeated. Just the second url will be fetched again.

  4. Redirect is marginally slower than forward, since it requires two requests.

  5. Objects placed in request scope are not available to second request.

  6. There are several ways to perform a redirect for example

    Http/1.1 301 moved permanently
    Location : http://www.foobar.org/
    <meta http-equiv="refresh" Content="0; URL=http://www.example.org/"/>
    <script type="text/javascript"> location.href ="http://www.foobar.org" </script>

Redirect Should be used when

  1. If you need to transfer of control to a different domain.

  2. To achieve separation of tasks.

For example, database update and data display can be separated by redirect. In this case if user presses F5 button the browser then only display part will execute again and not the database update part. Do the PaymentProcess and then redirect to the display payment info, if the client refreshes the browser, only the displayInfo will be done again and not the payment process. Use Forward when database SELECT operations are used


Top articles in this category:
  1. Java Concurrency Interview Questions and Answers
  2. Cracking core java interviews - question bank
  3. Top 30 Hibernate and Spring Data JPA interview questions
  4. Top 50 Multi-threading Java Interview Questions for Investment Bank
  5. RBS Java Programming Interview Questions
  6. UBS Top 10 Java Interview Questions
  7. Goldman Sachs Java Interview Questions for Senior Developer


Find more on this topic:
Java Interviews image
Java Interviews

Interview - Product Companies, eCommerce Companies, Investment Banking, Healthcare Industry, Service Companies and Startups.

Last updated 1 week ago


Recommended books for interview preparation:

This website uses cookies to ensure you get the best experience on our website. more info