What is the difference between sendRedirect() and forward()?
in what situations do we have to use send redirect()
instead of forward().
Answers were Sorted based on User's Feedback
Answer / ajay
sendRedirect() means it's client side redirect at that time
new parameters can be added.(i.e HttpRequest, HttpResponse)
forward() meand it's server side redirect at that time same
parameters can be used.
forward() can be used forwarding the request from one
servlet to jsp.(i.e with in the container).
redirect() can be used redirecting the one jsp to another
jsp(i.e different containers).
Is This Answer Correct ? | 56 Yes | 8 No |
When we use forward, then servlet container forwards all
request to the target page. but in the case sendRedirect,
container makes a new request to the target Page.
So in forward , url link doesn't change but in sendRedirect
url line change . Because container makes a new request,
sendRedirect is much slower than forward.
If a target page has no relation with current
page , then we can use sendRedirect(I think so....)
Is This Answer Correct ? | 35 Yes | 9 No |
Answer / vikram raj bakshi
I'll explain this with an example. If suppose u ask ur
servant(who is uneducated), to go to the market and get u a
Pepsodent.Now if the shopkeeper is not having a pepsodent
he will simply hand over Close Up to the servant.This
scenario is something simialr to the "forward" method. If
the requested resource is not available u will be
redirected to a different page whose url is specifiedd in
the forward method call. But u wont be able to see the
cnage in the url in the address bar. It's all done
internaly. In case os sendRedirect, its just like ur call
is moving from one page to another and u will able to see
the cnage in the url too. Its like normal page navigation.
Hope you would have a got a picture of it.
Is This Answer Correct ? | 25 Yes | 6 No |
Answer / guest
Both senredirect and forward metods are used to forward the
request to another resourse
but
1)the request dispatcher() is used when we want to redirect
the client requestto some other resourse (ie:out of context)
or whenver we want to redirect errors
where as
use forward()when we sending a page that is within in the
same site
2)forward() are executed on the serverside but send redirect
()are on the client side
jawahar
Is This Answer Correct ? | 13 Yes | 2 No |
Answer / neha rajpal
forward mean forwarding the requset to some another jsp or
servlet this is done by server we have do describe the page
in the forward method's argument note thatforward method
argument accept only string ..
while sendredirect is on client side . the new request
object is created.
Is This Answer Correct ? | 13 Yes | 6 No |
Answer / vinit sharma
Hello i am vinit and according to me,
Both methods are use to transfer form one web component to
another web component.
In case of forward () the same request (that have client
information) is passed from server side to the another page
(this another page should be in the same container (Web
Server)), due to URL remains same.
While in sendRedirect () a new request (due to
loss the previous request information) is generated from
client side to another page (this another page can be in
the same OR in different container (Web Server)), due to
URL becomes change.
Is This Answer Correct ? | 7 Yes | 0 No |
Answer / senthilraj
Using thse methods we can redirect one page to another page.
Using the sendReirect() we can connect any URL from
outide the web application.
Using forward() we can connect URL only within
the application.
Is This Answer Correct ? | 3 Yes | 0 No |
1.forward will forward the request without saving the client
information where as sendRedirect will save the previous
information and send to another requested page.
2.The forward operation happens in the same request itself.
Once if you forward a request, you cannot add any more
response content after the forward command. Becuase, the
servlet ignores the remaining things and forwards the
request to another servlet.
The send redirect is the one, which redirects you to some
other servlet or page. The redirection is not within the
same request, but it is a new request. Using send redirect,
you can access a page available on another context / server.
Is This Answer Correct ? | 11 Yes | 9 No |
Answer / anujkumar
sendRedirect()send the data one page to other page with
refernce other request but forward() send the data all at a
time in same server
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / aravind
forward() is a action element in jsp. it is used to pass
ctrl from current page to another jsp page and it is a
method in jsp.
send redirect() is a method in servlet.
there are two methods used. as
HttpServletResponse.encodeReDirctURL().which takes String
represents a redirction url.next sendredirect() method.
which takes the String returned from the
encoderedirectString() and send it back to the client for
redirection
Is This Answer Correct ? | 8 Yes | 10 No |
What are the j2ee client types?
What are web technologies in java?
What is general entity?
What are the differences between Ear, Jar and War files? Under what circumstances should we use each one?
What are j2ee concepts?
What is java ee sdk?
What is enterprise information system?
How long does it take to master java?
What is javac written?
What is a plugin in java?
What is declarative security ?
What is application client container?