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

How to make sure a servlet is loaded at the application startup?

549


How can we achieve transport layer security for our web application?

567


What do you mean by chaining in servlet?

568


What is servlet invoker?

600


Why is http protocol called as a stateless protocol?

535






What is difference between cookies and httpsession?

544


Explain the role of dispatcherservlet and contextloaderlistener.

603


Can we override servlet service method?

585


What do you mean by session tracking and also explain its techniques?

496


What is meant by Servlet? What are the parameters of service method?

593


What is a servlet context object?

617


How many servlet objects are created?

561


What is ServletConfig object?

606


Differentiate between the print writer and servlet output stream?

560


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

1853