Servlet RequestDispatcher

Servlet RequestDispatcher


Posted in : Java Posted on : November 18, 2011 at 7:04 PM Comments : [ 0 ]

In this example you will learn about how to use RequestDispatcher in Servlet.

Servlet RequestDispatcher

In this example you will learn about how to use RequestDispatcher in Servlet.

RequestDispatcher is an interface of javax.servlet package that takes request from the client (any one of the resource servlet, html, jsp etc) and forwards it through the another resource (by any one of the resource servlet, jsp, etc.) on the server. Object of RequestDispatcher is obtained via getRequestDispatcher() method of ServletRequest interface. In the parameter of this method request for the path of target resource is passed and it matches the path elements of ServletRequest object that it contains.

There are two methods of RequestDispatcher interface. these are as follows :

1. forward : This method is used when you have not required to include the content of the requested resource into the generated response, because when this method is called after the preliminary process to generate the response it flushed out the output of requested body.

syntax : void forward(request, response) throws ServletException, IOException

parameters :

request & response : These parameters must be the same as the responsding servlet service method object's are passed.

2. include : This method is used when you are required to include the content of the requested resource into the generated response.

syntax : void include(request, response) throws ServletException, IOException

parameters :

request & response : These parameters must be the same as the responding servlet service method object's are passed.

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics