What is the use of RequestDispatcher in servlet?

Answers were Sorted based on User's Feedback



What is the use of RequestDispatcher in servlet?..

Answer / tirupathi rao

RequestDispatcher is used to connect to another webresource
with in the same context.

RequestDispatcher
rd=ServletContext.getRequestDispatcher("url of resource");
rd.forward(req,res);----used to forward to another resource.
rd.include(req,res);----used to include other resource.

Is This Answer Correct ?    132 Yes 15 No

What is the use of RequestDispatcher in servlet?..

Answer / abhishek taneja

request dispatcher is used to transfer the value attributes
to servlets and jsps. the request diapatcher is use the
relative url and there is one more thing in request
dispatcher is (non -idempotant) means when u will do the
multiple submits then it will update the database again and
again so to avoid the multiple submits use the (Synchronizer
token pattern,PSG pattern,or sendRedirect)

Is This Answer Correct ?    29 Yes 17 No

What is the use of RequestDispatcher in servlet?..

Answer / bhudeep

RequestDispatcher is used to dispatch the request.that means
one resource take the ownership from another
resources (Servlets,jsps,htmls) available in the web
applicaions for handle the request.
we can get RequestDispatcher in two ways
1. servletContext.getRequestDispatcher("/absolute path");
2. servletRequet.getRequestDispatcher("relativepath");

now we can move to another resources with the following
methods available in RequestDispatcher
include(req,res);
forward(req,res);

Is This Answer Correct ?    21 Yes 12 No

What is the use of RequestDispatcher in servlet?..

Answer / sekharbabu

RequestDispatcher is used to move/call the another
resources (Servlets,jsps,htmls) available in the web
applicaions
we can get RequestDispatcher in two ways
1. servletContext.getRequestDispatcher("/path");
2. servletRequet.getRequestDispatcher("relativepath");

now we can move to another resources with the following
methods available in RequestDispatcher
include(req,res);
forward(req,res);

Is This Answer Correct ?    25 Yes 17 No

What is the use of RequestDispatcher in servlet?..

Answer / yuga.reddi08

RequestDispatcher is an interface,In a web application
having multiple webcomponents to handle a single request at
time we go for RequestDispatcher.
RequestDispatcher rd=servletRequest.getRequestDispatcher
("url of the webcomponent");
rd.inculude(request,response);
rd.forward(request,response);

Is This Answer Correct ?    34 Yes 27 No

What is the use of RequestDispatcher in servlet?..

Answer / kollu sreenivasa rao

When you want send your request to another servlet/jsp from
your servlet, we can use RequestDispatcher.

There are two ways to get reference of RequestDispatcher.

1)If you get requestdispatcher reference from
ServletContext, you have to specify the absolute url as
argument in getRequestDispatcher method like below.

RequestDispatcher dispatcher =

getServletContext().getRequestDispatcher("/my_other_app/servlet/SomeServlet");
dispatcher.forward(request, response);

2)If you get requestdispatcher reference from
ServletRequeset, you have to specify the relative url as
argument in getRequestDispatcher method like below.

RequestDispatcher dispatcher =
request.getRequestDispatcher("SomeServlet");
dispatcher.forward(request, response);

Is This Answer Correct ?    18 Yes 11 No

What is the use of RequestDispatcher in servlet?..

Answer / codventure

RequestDispatcher defines an object that receives the
request from client and sends them to any resources on the
server.

Is This Answer Correct ?    10 Yes 6 No

What is the use of RequestDispatcher in servlet?..

Answer / naresh

consider there are two servlet,such as "aservlet"
and "bservlet"
suppose a client requests "aservlet" ,which
inturn "aservlet" depends on "bservlet"
we must redirect the request from "aservlet" to "bservlet

this is done by two steps :-
1.RequestDispatcher disp= getServletContext
().getRequestDispatcher("/url of bservlet");
2.
2.1.- rd.forward(req,res);
2.2.-rd.include(req,res);

Is This Answer Correct ?    7 Yes 3 No

What is the use of RequestDispatcher in servlet?..

Answer / pramod p deore

RequestDispatcher is used to transfer the control to other
JSP or servlet.
RequestDispatcher rd= request.getRequestDispatcher
("result.jsp);
rd.forward (request, response);

Is This Answer Correct ?    9 Yes 6 No

What is the use of RequestDispatcher in servlet?..

Answer / devendra.m

RequestDispacher:
RequestDispacher is a interface,which is used to dispach a
request from servlet to another servlet.
consider there are two servlets.one servlet is having
business logic and another servlet is having presentation
logic.if you want to achieve these two tasks,(like wizard
application) these can be done by using request dispacher.

which means that whenever we making a request to sevlet1
from the browser,we are getting response,insted of getting
the respose from the servlet1, we want to delegate the same
request from servlet1 to servlet2.
here in RequestDispacher there are two more methods are
there....i.e forward() and include().
if you used forward() only destination servlet(i.e last
servlet) is eligible for construting the browser output.
if you used include() every servlet is eligible to construt
the browser output.

RequestDispacher rd = request.getRequestDispachet("/usrl
pattern of second servlet");
rd.forward(request,response);

//so once executing the this stmt,which is forwarding the
same request to next servlet and displying only last servlet
out put.

1. There is no difference b/w forward() and include() incase
of parameters and attributes.
attributes means obj incase of j2ee.
before calling the rd.forward(req,res) method if you want to
add any data or objects to the next servlet we can use some
methods which are there in request,session and application
request.setAttribute(key,"value"); //add the obj to the next
servlet and this method returs void
request.getAttribute(key,); //get the object ...and this
method returs obj
request.removeAttribute(key); // inorder to remove a
perticular obj we can use this method and this metho returs
void.

2. but remember that we can add the attributes,modify the
attributes and also we can remove the attributes in servlets
(attributes means objects).
but in case of parameters we can not add,modify and remove
from the servlets we can only read the parameters.(this is
main diff)

3.entire requesrdispatch operation can be done in server
side,client doesn't know any thing abut this.

4. by using requestdispatch we can dispatch a request from
one servlet to another servlet within the application
only...we can not send a request from one servlet of one
application into another servlet of another
application...(this is also important).

if you have any doubts pls reach me mdevendra@gmail.com

Is This Answer Correct ?    5 Yes 3 No

Post New Answer

More Servlets Interview Questions

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

0 Answers  


What are the phases of servlet life cycle?

0 Answers  


What is a servlet-to-servlet communcation?

0 Answers  


HTTP tunneling means what?

2 Answers  


How to deal with multi-valued parameters in a servlet?

2 Answers  






How can an existing session be invalidated?

0 Answers  


What is the servletconfig object?

0 Answers  


What is the purpose of requestdispatcher interface?

0 Answers  


which type of data passing is used in realtime?

1 Answers  


What's the difference between servlets and applets?

0 Answers  


What do you mean by cgi?

0 Answers  


What are the various ways of session supervision in servlets?

0 Answers  


Categories