What is difference between sendRedirect() and forward()..? Which one is faster then other and which works on server?

Showing Answers 1 - 10 of 10 Answers

vanraj

  • Jun 11th, 2005
 

When you invoke a forward request, the request is sent to another resource on the server, without the client being informed that a different resource is going to process the request. This process occurs completely with in the web container. When a sendRedirtect method is invoked, it causes the web container to return to the browser indicating that a new URL should be requested. Because the browser issues a completely new request any object that are stored as request attributes before the redirect occurs will be lost. This extra round trip a redirect is slower than forward.

J. P. Naidu

  • Jul 27th, 2005
 

sendRedirect method is in Request Object where as the forward is in the RequestDespatcher Object. 
 
In forward, request and respone objects are available to the forwarded page where it is not possible in sendRedirect

  Was this answer useful?  Yes

J. P. Naidu

  • Jul 28th, 2005
 

Quote:


sendRedirect method is in Request Object

 
Correction of the above: it is in response object

  Was this answer useful?  Yes

Venkatesh

  • Sep 2nd, 2005
 

"sendRedirect" is a Response Object, but not a Request Object. Please.. Don't mis guide...

  Was this answer useful?  Yes

Actually when we use sendRedirect method then u r changing or transfering the request to new URL.Mean new URL is formed .In case of Forward method of RequestDispatcher your context is not changed means ur URL object remains same.Since URL is same so forward() method is faster than sendRedirect one.Also in case of sendRedirect() method when u reach to new page the request/value at previous one is lost.

Also forward() method is handled from server to server but sendRedirect() method is not.

  Was this answer useful?  Yes

rameshvdnv

  • Apr 25th, 2007
 

The difference between sendRedirect() and forward() is nothing but it will redirect to a resource that is available in a webcontainer or in another webcontainer and that resource will be executed from the browser.
    Suppose if we use forward()the requestdispatcher forwards the request to the specified jsp(servlet)and the called jsp(servlet)result(o/p)will be sent to the browser.

  Was this answer useful?  Yes

NarendrababuThumati

  • Jul 11th, 2007
 

In forword() the request is sent to another page with in the webapplication only.
where as response.sendredirect() will sent the respone to another web application.

  Was this answer useful?  Yes

Deepak Tewari

  • Oct 23rd, 2007
 

In simple words we say

  1. response.sendRedirect takes full round trip ie goes to the browser and comes back to the server where as forward is server to server transfer
  2. response.sendRedirect makes a new request so all previous request parameters are lost and in order to persist the data you need to send through query stringĀ  where as in forward the old request is forwarded so all old request data persist

  Was this answer useful?  Yes

forward() can be used only within same application and response is send by the forwarded servlet.while send Redirect can also be be used outside the the application (requested servlet must be deploy on the the same webserver)and one more thing the request is send by browser to the requested servlet not by a servlet.
both works on servers

  Was this answer useful?  Yes

paramsethi

  • Apr 8th, 2010
 

In addition to all of the above answers, one point of difference that was missed is,

The forward method takes the relative URL to the servlet, where as sendRedirect method requires the full URL of the destination.

  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.

Answer Question

Click here to Login / Register your free account


 
Send   Reset

 

Related Answered Questions

 

Related Open Questions