| Author |
What is difference between RequestDispatcher() and sendRedirect()?
|
Mak Smash
Greenhorn
Joined: May 15, 2011
Posts: 17
|
|
What is difference between RequestDispatcher() and sendRedirect()??
|
 |
Manjula Weerasinghe
Greenhorn
Joined: Mar 15, 2010
Posts: 25
|
|
Hi Mak,
RequestDispatcher forward method pass the control of the request to another servlet or jsp without telling anything about the request dispatch to the client browser. Therefore client browser don't know whether the returned resource is from an another servlet/jsp or not.
sendRedirect method stop further processing of the request and send http status code "301" and URL of the location to be redirected to the client browser in the response header. Server does not have control of this request after sending the redirect related HTTP header to the client browser. Client browser sees http status 301 and then it know it should send a new request to the url in "Location" http header which is set by server. and Client browser sends a new request to the new URL and it will be processed by the server as another normal request.
Therefore request dispatch happens completely in the server side.
But sendRedirect is handle through the client browser.
Thanks & Regards,
Manjula
|
OCPJP 6, OCE JEE 6 JSP and Servlet Developer
|
 |
Bosun Bello
Ranch Hand
Joined: Nov 06, 2000
Posts: 1506
|
|
|
Good response from Mandula. This is a common question and is in the FAQ.
|
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
|
 |
Mak Smash
Greenhorn
Joined: May 15, 2011
Posts: 17
|
|
|
What is the key difference between using a < jsp:forward > and HttpServletResponse.sendRedirect()
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56185
|
|
|
Same answer.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Mak Smash
Greenhorn
Joined: May 15, 2011
Posts: 17
|
|
Is this right to say < jsp:forward > runs on server side and HttpServletResponse.sendRedirect() runs on client side?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56185
|
|
Not really. They both run on the server. But, a sendRedirect causes a status code to be sent to the browser that instructs it to make a new request to the redirect URL.
|
 |
 |
|
|
subject: What is difference between RequestDispatcher() and sendRedirect()?
|
|
|