• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

difference b/w forward & sendRedirect

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the difference between RequestDispatcher.forward(request req,response res)
And response.sencRedirect("url");?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Send redirect sends a "location" header to the browser.
The browser then initiates a new request.
  • Browser requests page A
  • Server says go look for B
  • Browser requests B
  • Server returns page B

  • The browser knows that it is showing page B.
    The address window will have the URL for page B.


    With forward, the whole process occurs on the server.
  • Browser requests page A
  • Server returns page B

  • As far as the browser knows, its looking at page A.
    The address window in the browser will show the url
    for page A.

    Forward should be a little faster because it doesn't involve the extra round trip (small difference, a redirect only returns the headers). It's useful in an MVC pattern when you want to forward to a JSP (or other web resource) that you wouldn't want the user trying to access directly.

    There are other advantages and disadvantages to both.
    [ March 22, 2005: Message edited by: Ben Souther ]
     
    Ranch Hand
    Posts: 94
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    In addition to ben

    Redirects can redirect the request off of the local server as well, but forward works only on local server.
     
    Ranch Hand
    Posts: 1491
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Using RequestDispatcher.forward(request req,response res), can i forward to antoher server (or) within the same server?
     
    Ranch Hand
    Posts: 213
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Kri,

    You can forwad only to resource available in your current web application.
     
    knowledge is the difference between drudgery and strategic action -- tiny ad
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic