File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sendRedirect vs Foward

 
Leonardo Pilatti
Greenhorn
Posts: 6
  • 0
  • 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: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • 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
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Isaias and Bibeault
 
Mark Stein
Ranch Hand
Posts: 75
  • 0
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic