jump to navigation

Forward Vs Redirect August 12, 2006

Posted by Allu in J2EE.
trackback

A Controller servlet may perform either a forward or a redirect operation at the end of processing a request.

Forward

  • forward is performed internally by the servlet
  • the browser is completely unaware that it has taken place, so its original URL remains intact
  • any browser reload will simple repeat the original request, with the original URL

Redirect

  • redirect is a two step process, where the web application instructs the browser to fetch a second URL, which differs from the original
  • a browser reload of the second URL will not repeat the original request, but will rather fetch the second URL
  • redirect is always slower than a forward, since it requires a second browser request
  • beans placed in the original request scope are not available to the second request

Forward should be used if the operation can be safely repeated upon reload; otherwise, redirect must be used. Typically, if the operation performs an edit on the datastore, then a redirect, not a forward, is required.

Advertisements

Comments»

1. Java Donkey - The Java Donkey comments on Java programming as well as other topics. » Struts Forward versus Redirect - April 17, 2007

[…] is an interesting blog regarding Forward vs Redirect This entry is filed under Struts. You can follow any responses to this entry through the RSS 2.0 […]

2. ashish - April 25, 2007

Marvellous explanation. But just provide an example of both the methodology.

3. m - January 10, 2008

forward and include

Briefly explain what these two methods do and when you would use one or the other. You can use a picture to illustrate the different message paths.

Answer?

4. Java interview Questions « Java Stuff - September 13, 2008

[…] Forward Vs Redirect […]

5. Michel - February 7, 2009

cool, thanks!

6. Joe - January 15, 2010

Does google mind forward? I know that redirect 301 works fine regarding SEO.

7. snimavat - April 9, 2010

Nice explanation..
This tutorials also explain with example http://www.jsptube.com/examples/response-sendredirect-servlet.html

8. Lorrie Dewayne - March 6, 2013

Hello just wanted to give you a brief heads up and let
you know a few of the pictures aren’t loading correctly. I’m not sure why but I think its a
linking issue. I’ve tried it in two different internet browsers and both show the same outcome.

9. Donna - May 24, 2013

First of all I want to say terrific blog! I had
a quick question which I’d like to ask if you do not mind. I was interested to know how you center yourself and clear your head before writing. I’ve had a tough time clearing my mind in getting my thoughts out there.
I truly do take pleasure in writing but it just seems like the first
10 to 15 minutes are usually wasted just trying to figure out how to begin.
Any ideas or tips? Many thanks!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: