Ropardo Sowftware development company

Experience software development with ROPARDO S.R.L.

RSS Feed
RSS Feed
  • Home
  • About ROPARDO S.R.L
  • Our websites

Forward vs Redirect

A Controller servlet may perform either a forward or a redirect operation at the end of processing a request in order to get to the results page.

Let’s say a browser requests page “A” in an application. If the application responds by forwarding to “B”, then a
server-side forward takes place; the server sends back the contents of “B” but the browser doesn’t know the difference. It asked for “A” and got something back that happened to actually
be “B”.
When redirect is invoked, it causes the web container to return to the browser a response indicating that a new URL should be requested. Because the browser issues a completely new request, any objects that are stored as request attributes before the redirect occurs will be lost. This is one of the biggest differences between a forward and a redirect.
If the applications responds by redirecting to “B”, then the server sends back a message saying “please ask me for B”. The browser then requests “B” and gets it.
Either way it gets the same thing, but the mechanism is quite different.

An example of when you need redirect that comes to mind is when
you want to forward to a URL on another server…(suppose you need some data from googlemaps) you can’t do a server-side forward in that case.
Or,another case, if the operation performs an edit on the datastore, then a redirect, not a forward, is required. This is simply to avoid the possibility of accidentally duplicating an edit to the database.

Advantages of using redirect over a forward

  • when you “refresh” the page it only refreshes the page that was redirected to. Often after a “save” request, you redirect to a “display” page. If that page is refreshed it just redoes the “display”, rather than “save and display” which is what would happen if you used a forward.
  • no confusion over relative links.

The advantages of using a forward over a redirect

  • doesn’t require a round trip for the client to reissue a new request. A redirect obviously involves some more overhead to get from A to B, so to speak.
  • retains all request attributes/parameters (lost on redirect)

Disadvantage:

  • can be confusing for relative urls from your pages. ie you request “/saveUser” which forwards to “/jsp/user/saveSuccess.jsp”. Relative links would be resolved from “/saveUser” which can be confusing. Solution – use an html <base> tag
  • the “refresh” problem

Below is a table with differences between forward and redirect, as seen on here

Forward Redirect
* forward is performed internally by the servlet * redirect is a two step process, where the web application instructs the browser to fetch a second URL, which differs from the original
* the browser is completely unaware that it has taken place, so its original URL remains intact * a browser reload of the second URL will not repeat the original request, but will rather fetch the second URL
* any browser reload will simple repeat the original request, with the original 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
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
Get Shareaholic
Tags: browser response forward redirect request servlet

 Posted in: Web Development
October 7, 2009 | Alina Hila | No Comments

Leave a Reply

 


  • « Previous post
  • Next post »
  • Recent Posts

    • Installing PyGraphviz on Windows
    • Convert python object to XML representation
    • Liferay Portlet Development
    • Norway Road Show 2011 private meeting invitation
    • Oracle OpenWorld 2011
  • Ropardo is Hiring

  • Subscribe

    • Add to Google Reader or Homepage Add to netvibes TopOfBlogs
  • Recent Comments

    • Rajkumar Pomaji on Bluetooth PC Remote Control
    • Stelian Morariu on GWT 2.1 – Uploading a file using the RPC mechanism
    • Sergio on GWT 2.1 – Uploading a file using the RPC mechanism
    • Artem on Liferay: Deployment will start in a few seconds… and how to realy start
    • rkd80 on GWT 2.1 – Uploading a file using the RPC mechanism
  • Archives

    • November 2011 (1)
    • September 2011 (4)
    • July 2011 (3)
    • June 2011 (2)
    • May 2011 (4)
    • April 2011 (4)
    • March 2011 (3)
    • February 2011 (2)
    • January 2011 (2)
    • December 2010 (1)
    • November 2010 (4)
    • October 2010 (4)
    • August 2010 (3)
    • July 2010 (3)
    • June 2010 (6)
    • May 2010 (8)
    • April 2010 (7)
    • March 2010 (9)
    • February 2010 (6)
    • January 2010 (5)
    • December 2009 (7)
    • November 2009 (9)
    • October 2009 (10)
    • September 2009 (14)
    • August 2009 (10)
    • July 2009 (1)
    • June 2009 (1)
    • May 2009 (1)
    • April 2009 (1)
    • March 2009 (1)
    • October 2008 (3)
    • October 2007 (3)
    • July 2007 (4)
    • June 2007 (1)
    • May 2007 (3)
  • Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
  • Categories

    • News (15)
    • Ropardo Team (8)
    • Ropardo Products (6)
      • File Tracking Client (4)
      • iManagement (2)
    • Software Development (83)
      • Microsoft.NET (22)
      • Java (40)
      • Oracle (8)
      • Power Builder (3)
      • Liferay (5)
      • Lotus Notes (9)
      • xWiki (4)
    • System Adminstration (13)
      • Linux (10)
      • Windows (3)
    • Programming (1)
    • Uncategorized (3)
    • Databases (10)
      • MSSQL (5)
      • PostgreeSQL (3)
    • Microsoft.NET (1)
    • Web Development (28)
      • ASP/ASPX (3)
      • Content Management Systems (1)
      • HTML/CSS (5)
      • Javascrip/AJAX (8)
      • PHP (7)
    • Oracle E Business Suite (6)
  • Tags

    .NET ajax blog C# certification client CMS control css database Debugging django Domino Eclipse extension file tracking filter fun gentoo google Hibernate how to html image iManagement import Java javascript jQuery liferay Linux Lotus Notes lotus script Oracle Oracle BI Publisher 11g PHP portal PostgreSQL powerbuilder Python SQL Telerik velocity xml Xwiki

© 2010 ROPARDO s.r.l..

Powered by WordPress. Styled by Ropardo