Google

Saturday, November 10, 2007

J2EE Interview Questions

What is the difference between sendRedirect() and forward()?

in what situations do we have to use send redirect()

instead of forward().

Question Submitted By :: Deepa

I also faced this Question!!     Rank     Answer Posted By


 

     Re: What is the difference between sendRedirect() and forward()? in what situations do we have to use send redirect() instead of forward().

Answer

# 1    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).

    0     Ajay


 

     Re: What is the difference between sendRedirect() and forward()? in what situations do we have to use send redirect() instead of forward().

Answer

# 2    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....)

    0     Bindhu Solomon


 

     Re: What is the difference between sendRedirect() and forward()? in what situations do we have to use send redirect() instead of forward().

Answer

# 3    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

    0     Aravind


 

     Re: What is the difference between sendRedirect() and forward()? in what situations do we have to use send redirect() instead of forward().

Answer

# 4    sendRedirect() can be used to send a request with in the

server or in other server.

forward() can be used to send request in the same server.

    0     Sateesh.b


 

     Re: What is the difference between sendRedirect() and forward()? in what situations do we have to use send redirect() instead of forward().

Answer

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

    0     Neha Rajpal

No comments: