• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

sendRedirect vs Foward

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anyone knows the diference between RequestDispatcher.foward and HttpServletResponse.sendRedirect?
I mean in any terms (performance, funcionability, etc).
thanks in advice
Leonardo Pilatti
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a nutshell; a forward routes the request instance directly to the specified resource, while a redirect causes the browser to make a new request to the specified resource.
There are other nuances, but the main difference is that the foward takes place in the context of a single request (meaning that any request attributes you have placed on the request remain intact), versus the redirect which spawns a new request.
hth,
bear
[ December 03, 2002: Message edited by: Bear Bibeault ]
 
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
With RequestDispatche().foward(), you can call only resources of your server.
With HttpServletResponse.sendRedirect, you can call resources out of you server. Example:
response.sendRedirect("http://site.com")
By
 
Leonardo Pilatti
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Isaias and Bibeault
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Two other things to keep in mind...
forward takes the argument (ServletRequest, ServletResponse) so parameters, session, etc. can be passed.
sendRedirect doesn't pass anything with it (unless you write it onto the end of the URL).
Also, forward is transparent to the browser, while sendRedirect isn't.
MS
reply
    Bookmark Topic Watch Topic
  • New Topic