Read more: http://javarevisited.blogspot.com/2011/09/sendredirect-forward-jsp-servlet.html#ixzz2xmpb4zvh
Forward()
|
SendRediret()
|
When we use forward method request is transfer to other resource within the same server for further processing.
|
In case of sendRedirect request is transfer to another resource to different domain or different server for futher processing.
|
In case of forward Web container handle all process internally and client or browser is not involved.
|
When you use SendRedirect container transfers the request to client or browser so url given inside the
sendRedirect method is visible as a new request to the client.
|
When forward is called on
requestdispatherobject we pass request and response object so our old request object is present on new resource which is going to process our request
|
In case of SendRedirect call old request and response object is lost because it’s treated as new request by the browser.
|
Visually we are not able to see the forwarded address, its is transparent
|
In address bar we are able to see the new redirected address it’s not transparent.
|
Using forward () method is faster then send redirect.
|
SendRedirect is slower because one extra round trip is required beasue completely new request is created and old request object is lost.Two browser request requird.
|
When we redirect using forward and we want to use same data in new resource we can use request.setAttribute () as we have request object available. (
That means you can not add any url parameter in the forward, you can not changed the original url in a way. So, if you want to pass any data to the next servlet or jsp. we can use setAttribute and getAttribute. Please remember forward is in the same context.)
|
But in sendRedirect if we want to use we have to store the data in session or pass along with the URL.
|
Read more: http://javarevisited.blogspot.com/2011/09/sendredirect-forward-jsp-servlet.html#ixzz2xmpgi4Ie
see also: http://javarevisited.blogspot.com/2011/09/sendredirect-forward-jsp-servlet.html