Difference between forward and sendRedirect

What is difference between forward and sendRedirect

Questions by dnjswaroopa

Showing Answers 1 - 8 of 8 Answers

vijay tandel

  • Jun 19th, 2006
 

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 

  Was this answer useful?  Yes

Vijay Jaiswal

  • Jun 23rd, 2006
 

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 

 

 

 

  Was this answer useful?  Yes

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.

  Was this answer useful?  Yes

sivamscs

  • Jul 29th, 2006
 

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

  Was this answer useful?  Yes

tshayine

  • Aug 4th, 2006
 

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.

  Was this answer useful?  Yes

niranjan

  • Aug 8th, 2006
 

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.

  Was this answer useful?  Yes

Rukmangada K J

  • Oct 12th, 2006
 

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....

  Was this answer useful?  Yes

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

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions