Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

sendRedirect & forward

 
varun bihani
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the exact difference between response.sendRedirect() and forward tags in JSP?
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sendRedirect() results in the server sending a HTTP redirect response to the client saying "please, go to this URL" while forward() (also called "server-side forward") passes on the request processing responsibility to another resource such as a servlet or a JSP page.
 
varun bihani
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What difference does it make??
means in sendRedirect will the code written after the command will execute or it will just redirect to the url specified from that point only without compiling the rest of the code.
 
Nischal Tanna
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If u use sendRedirect ..
1.A new request is forwarded to the destination page i.e., its a round the way trip means the source first redirects to the client i.e,the browser and then from the browser , the destination page is forwarded a request.
2.It is advisable to use these method when the control has to be forwarded to a page which is on a different server.
If u use jsp:forward
1.The original request is forwarded to the destination page i.e, no new request object is created.
2.It is widely used when both the source as well as destination page reside in the same server.Thus this method is a whole server side process n no going back to browser.
I hope this works out.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!