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>
What is difference between HTTP Redirect and Forward
Carvia Tech | August 05, 2019 | 2 min read | 28 views
Http Forward
-
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.
-
When forward is done, the original request and response objects are transferred along with the additional parameters if needed.
-
Forward can’t transfer control to some other domain.
-
Original URL at the client side remains intact, refreshing the page will cause the whole step to repeat again.
-
Session object is not lost in forward or redirect.
Http Redirect
-
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.
-
Server sends Http Status Code of 301 to the client, and then client follows the instructions.
-
If someone reloads the page on browser, then original request will not be repeated. Just the second url will be fetched again.
-
Redirect is marginally slower than forward, since it requires two requests.
-
Objects placed in request scope are not available to second request.
-
There are several ways to perform a redirect for example
Redirect Should be used when
-
If you need to transfer of control to a different domain.
-
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:
- Java Concurrency Interview Questions and Answers
- Cracking core java interviews - question bank
- Top 30 Hibernate and Spring Data JPA interview questions
- Top 50 Multi-threading Java Interview Questions for Investment Bank
- RBS Java Programming Interview Questions
- UBS Top 10 Java Interview Questions
- Goldman Sachs Java Interview Questions for Senior Developer
Find more on this topic:

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:
Similar Posts
- Send GMAIL emails from Java and Spring
- Send Mandrill emails from Spring Boot in Java
- Top 30 Hibernate and Spring Data JPA interview questions
- Generating variable length secure key/secret in Java
- Reverse the bits of a number and check if the number is palindrome or not
- MD5 and SHA-256 in Java Kotlin and Android
- Spring Security 5 - There is no PasswordEncoder mapped for the id
- Inter-thread communication in Java
- What are different thread states in Java
- Static method synchronization aka Class Lock in Java
Enter your email address to subscribe to this blog and receive notifications of new posts by email.