GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE
Go To First  |  Previous Question  |  Next Question 
 J2EE  |  Question 47 of 104    Print  
Difference between forward and sendRedirect
What is difference between forward and sendRedirect


  
Total Answers and Comments: 8 Last Update: October 13, 2006     Asked by: dnjswaroopa 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
June 19, 2006 12:55:11   #1  
vijay tandel        

RE: what is difference b/n forward and sendRedirect

forward : when forward is used server forwards the request to the new url and the control stays on the same page. in other words it just forward the request to new ur and come back fomr where forward is called.

sendRedirect : sendRedirect forward the request to url as new request and the cotrol goes to the destination page and never come back to the calling page


 
Is this answer useful? Yes | No
June 23, 2006 11:45:06   #2  
Vijay Jaiswal        

RE: what is difference b/n forward and sendRedirect

Send Redirect
when you use send redirect it will rediredct the url to new url
and It will be displayed in browser
EX:
suppose u are in the page
http://162.0.0.1/submit.jsp and u r redircting url

response.sendRedirect(http://162.1.1.0/error.html);

then in browser url will changed and u will see error.html

Forward
When you use forward it will forward to particular page but in browser forwarded url won't dispaly
<jsp:forward page http://162.1.1.0/error.html) />

In browser u will see same url but it is the error.html page


 
Is this answer useful? Yes | No
July 24, 2006 13:47:27   #3  
srinivasaraobora Member Since: May 2006   Contribution: 31    

RE: what is difference b/n forward and sendRedirect

Hi

The main difference is by using forward we can't forward the resource availble in other webserver / applicationserver .but by using sendRedirect we can achieve that.

keeps smiling and mailing

bora_srinivasarao@yahoo.co.in

HELP EVER HURT NEVER & IMPOSSIBLE AS POSSIBLE

Note:If any one want java materials like e-books faq's send a mail to my id.if any doubts regarding java send a mail to my id if possible i will send answers.if any one want how to install java softwares tomcat weblogic eclipse jbuilder etc and how to use plz send amil or ask online also i will definitly tell.


 
Is this answer useful? Yes | No
July 29, 2006 07:30:43   #4  
sivamscs Member Since: July 2006   Contribution: 3    

RE: what is difference b/n forward and sendRedirect
Forward will dispatch the request to a particular resource and the output is displayed based on that file. Whereas sendRedirect allows a round trip to generate a new request from the browser to the target page
 
Is this answer useful? Yes | No
August 04, 2006 04:32:12   #5  
tshayine Member Since: August 2006   Contribution: 1    

RE: what is difference b/n forward and sendRedirect
When the sendRedirect( ) method is invoked it causes the web container to return to the browser a response indicating that a new URL should be requested. Because the browser issues a completely new request any objects that are stored as request attributes before the redirect occurs will be lost. This is one of the biggest differences between a forward and redirect.
 
Is this answer useful? Yes | No
August 08, 2006 12:04:12   #6  
niranjan        

RE: what is difference b/n forward and sendRedirect

In response.sendRedirect we have to give the absolute path of the url and also rerequest and response objects will be send to the new page automatically .But in forward method we have to pass request and response objects to the new page explicitly.

forward() passews the request to the destinationj url that should be within the servletContext where as response.sendredirect passes to the destination url whether on the same domain or some other domain.


 
Is this answer useful? Yes | No
October 12, 2006 20:54:18   #7  
Rukmangada K J        

RE: what is difference b/n forward and sendRedirect
in sendRedirect we can forward the request to the file in another context path but in case of forward() method it only invokes the file within the context path....
 
Is this answer useful? Yes | No
October 13, 2006 01:42:38   #8  
srinivasaraobora Member Since: May 2006   Contribution: 31    

RE: what is difference b/n forward and sendRedirect

Hi

The forward action allows the request to be forwarded to another resource (servlet/jsp/HTMl> which are available in the same web-application (context).
Where as in the case of Response.sendRedirect() the request to be forwarded/redirected to another resource in the same web-application or some other web-application in the same server or to a resource on some other web-server. The key difference is by using <jsp:forward> single request from a browser can process multiple resources. Where as by using SendRedirect() multiple requests take place in order to process multiple resources.

ok bye.......keep in touch

do reply

keeps smiling and mailing

bora_srinivasarao@yahoo.co.in
Hyderabad

HELP EVER HURT NEVER & IMPOSSIBLE AS POSSIBLE

Note:If any one want java materials like e-books faq's send a mail to my id.if any doubts regarding java send a mail to my id if possible i will send answers.if any one want how to install java softwares tomcat weblogic eclipse jbuilder etc and how to use plz send amil or ask online also i will definitly tell.
see my profile by clickon below link: http://in.geocities.com/bora_srinivasarao/MyHomepage.html

java: http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/DEA2eIX.html


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape