Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sendRedirect vs Foward

 
Leonardo Pilatti
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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 ]
 
Isaias C. Barroso
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks Isaias and Bibeault
 
Mark Stein
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic