Servlet Chaining means the output of one
servlet act as a input to another servlet.
Transfering the control from one servlet
to another servlet.
How do we perform
• This method is declared
in RequestDispatcher Interface.
• Signature: forward(ServletRequest request,
• This method is declared in
• Signature: void sendRedirect(String url)
The RequestDispacher interface provides
the facility of dispatching the request to
another resource it may be html, servlet
or jsp.This interface can also be used to
include the content of antoher resource
also. It is one of the way of servlet
There are two methods defined in the
The RequestDispatcher interface provides two
methods. They are:
public void forward(ServletRequest
a request from a servlet to another resource
(servlet, JSP file, or HTML file) on the server.
public void include(ServletRequest
the content of a resource (servlet, JSP page, or
HTML file) in the response.
//servlet2 is the url
//pattern of the second servlet
rd.forward(request, response);//method m
ay be //include or forward
When we want that someone else should
handle the response of our servlet, then
there we should use
This method is in HttpServletResponse
It is used to redirect response to another
resource, it may be servlet, jsp or html
In send Redirect whenever the client makes any
request it goes to the container, there the
container decides whether the concerned servlet
can handle the request or not.
If not then the servlet decides that the request
can be handle by other servlet or jsp. Then the
servlet calls the sendRedirect() method of the
response object and sends back the response to
the browser along with the status code.
Then the browser sees the status code and look
for that servlet which can now handle the
Again the browser makes a new request,
but with the name of that servlet which
can now handle the request and the
result will be displayed to you by the
browser. In all this process the client is
unaware of the processing.