ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage   interview questions urls   External Links  Contact Us     Login  |  Sign Up                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories  >>  Software  >>  Java J2EE  >>  Java Related  >>  J2EE
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
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).
 
Is This Answer Correct ?    6 Yes 1 No
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....)
 
Is This Answer Correct ?    5 Yes 1 No
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
 
Is This Answer Correct ?    1 Yes 2 No
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.
 
Is This Answer Correct ?    1 Yes 1 No
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.
 
Is This Answer Correct ?    0 Yes 2 No
Neha Rajpal
 
  Re: What is the difference between sendRedirect() and forward()? in what situations do we have to use send redirect() instead of forward().
Answer
# 6
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 ?    2 Yes 0 No
Guest
 
  Re: What is the difference between sendRedirect() and forward()? in what situations do we have to use send redirect() instead of forward().
Answer
# 7
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 ?    3 Yes 0 No
Bhupathi.vm
[Sirahu Technology]
 
  Re: What is the difference between sendRedirect() and forward()? in what situations do we have to use send redirect() instead of forward().
Answer
# 8
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 ?    2 Yes 0 No
Vikram Raj Bakshi
 

 
 
 
Other J2EE Interview Questions
 
  Question Asked @ Answers
 
i developed a Stateless Session bean program.And created a client by a common java class as class m {p s v m(String s[]){....}} And i called the bean deployed in weblogic.from cmd prompt And that run. mind it i have to set setenv,seting classpath for that bean jar file before compile and run it. ok when i do a servlet programme deployed in tomcat and call that bean then it give classdefnotfoundException and NoInitialContext like this.So how i sucessfully do this? Ok when i call that bean from java class from the console like i previously told, if i don't set setenv i found the same error on the cmd prompt. pls help to get out of it  1
what is Directory Structure of webapplication? CTS5
what is the difference between Tomcat 4 & Tomcat 5? TCS1
to update a batch in a table in jdbc which method of statement object is used  1
How can we serialize a jsp page. CSC2
to update a batch in a table in jdbc which method of statement object is used. Polaris2
Name the Implicit variable which is used to access other implicit objectes present in JSP. AZTEC6
Explain about J2EE Application Architecture  1
What is the difference between sendRedirect() and forward()? in what situations do we have to use send redirect() instead of forward(). Mind-Tree8
i have to create an application with session.during that session a timer will be started & show the time in second upto the session expired.So that i can know how many time i in that session. Hint:-i m hinted that it will coded with javascript Wipro1
 
For more J2EE Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com