File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes sendRedirect & forward Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "sendRedirect & forward" Watch "sendRedirect & forward" New topic
Author

sendRedirect & forward

varun bihani
Ranch Hand

Joined: Aug 11, 2003
Posts: 96
What is the exact difference between response.sendRedirect() and forward tags in JSP?


<a href="http://www.galaxyweblinks.com" target="_blank" rel="nofollow">www.galaxyweblinks.com</a><br /><a href="http://www.freechatcode.com" target="_blank" rel="nofollow">www.freechatcode.com</a><br /><a href="http://www.onlinefamilytreemaker.com" target="_blank" rel="nofollow">www.onlinefamilytreemaker.com</a>
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
varun bihani
Ranch Hand

Joined: Aug 11, 2003
Posts: 96
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

Joined: Aug 19, 2003
Posts: 182
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.


Thnx
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: sendRedirect & forward
 
Similar Threads
Exam Results
Inter Servlet Communication
enable/disable Buttons
WA #1.....word association
Free chapters of The Joy of Clojure are coming properly