Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What is the use of RequestDispatcher in servlet?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Why is httpservlet declared abstract?

1116


Is servlet a controller?

1007


How do you invoke a Servlet? What is the difference between doPost method and doGet method?

1144


What is the difference between 2 types of servlets?

1145


What do you mean by cgi and what are its drawbacks?

982


What is the difference between the include() and forward() methods?

1082


What are the types of protocols supported by httpservlet ?

1222


Write a hello world program using servlets.

1063


What methods do you use in servlet - applet communication?

1042


Explain the war file?

1067


What is a cookie What is the difference between session and cookie

1077


What are the exceptions thrown by servlets? Why?

1168


What is called servlet container?

1089


How do we call one servlet from another servlet?

1044


Define the servlet mapping.

1049