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

Which java application server is the best?

978


What are the common methods that are included in the http servlet class?

993


What are the disadvantages of storing session state in cookies?

1088


What is the effective way to make sure all the servlets are accessible only when user has a valid session?

1002


Is servlet thread safe?

932


Explain the different ways for servlet authentication?

1028


What are the jobs performed by servlets?

1002


What are the types of Session Tracking ?

1083


What are the supporting protocol by HttpServlet ?

1111


What is the capacity the doget can send to the server?

1016


What are different ways for servlet authentication?

1042


Define the life cycle of a servlets.

1004


Given the request path below, which are context path, servlet path and path info?

986


What is the main purpose of java servlets?

999


Why the container loads server at the application startup and how?

1008