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

Explain jsessionid and when is it created?

1066


What is servlet container?

1089


Explain the difference between servlet and cgi?

1128


Explain the features are in servlet 3?

1027


What is difference between server and servlet?

1057


What is the difference between servlet and jsp?

1079


Why don't we write a constructor in a servlet?

1008


What is the disadvantage of cookies?

967


What mechanisms are used by a Servlet Container to maintain session information?

1135


Describe servlet?

993


What are some advantages of storing session state in cookies?

987


What methodology can be followed to store more number of objects in a remote server?

2235


Define the servlet mapping.

1004


What is servlet and its use?

1068


What is cookies in servlet with example?

1053