Difference between Include, Forward and sendRedirect in
Servlet?

Answer Posted / md.farookh.mb

Response.sendRedirect () This function is used, when we
want to redirect
the client request to some other site (i.e out of our
context) or
when ever we want to redirect errors. If you are using
sendRedirect (), then it will be visible to the client that
means the URL which you have been redirected will be
visible in the address bar. Redirect response to the client
using the specified redirect location URL.

RequestDispatcher Interface:
Forward() : This can be done in two ways by Request &
ServeletContext.
Forwarding a request from a servlet to another resource
(servlet, JSP
file, or HTML file) on the server. Forward is done at
server side, without the client's knowledge.

When you invoke a forward request, the request is sent to
another
resource on the server, without the client being informed
that a
different resource is going to process the request. This
process occurs
completely with in the web container. When a sendRedirtect
method is
invoked, it causes the web container to return to the
browser indicating
that a new URL should be requested. Because the browser
issues a
completely new request any object that are stored as
request attributes
before the redirect occurs will be lost. This extra round
trip a
redirect is slower than forward.
Include:Includes dynamic page information..

Is This Answer Correct ?    130 Yes 15 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Whether thread can be used in servlets?

730


What is the advantage of Servlets when compared with other server side technologies?

1861


Why is http protocol called as a stateless protocol?

537


What are the type of protocols used in httpservlet?

616


What is servlet in web technology?

577






Write all the phases defined in servlet life cycle?

589


Can you create a deadlock condition on a servlet?

589


What is meant by session? Tell me something about httpsession class?

605


What are the important functions of filters?

601


What is meant by a servlet?

606


What is a servlet?

611


What do you mean by mime type?

556


What are the differences between forward() method and sendredirect() methods?

553


What is the difference between the getrequestdispatcher(string path) method of javax.servlet.servletrequest interface and javax.servlet.servletcontext interface?

569


A client sends requests to two different web components. Both of the components access the session. Will they end up using the same session object or different session ?

614