javax.servlet
Interface RequestDispatcher


public abstract interface RequestDispatcher

This interface implements methods to forward a request or include output from another (active) source such as another servlet.

A servlet can get an object that implements this interface from the ServletContext by calling the getRequestDispatcher() method.

If the servlet engine can it should provide a (wrapper) object which implements this interface when a servlet calls getRequestDispatcher().

Since:
Servlet API 2.1
Version:
Servlet API 2.1
See Also:
ServletContext.getRequestDispatcher(java.lang.String)

Method Summary
 void forward(ServletRequest request, ServletResponse response)
          Forwards a ServletRequest to the resource represented by the RequestDispatcher.
 void include(ServletRequest request, ServletResponse response)
          Includes into the ServletResponse any output written by the resource represented by the RequestDispatcher.
 

Method Detail

forward

public void forward(ServletRequest request,
                    ServletResponse response)
             throws ServletException,
                    java.io.IOException
Forwards a ServletRequest to the resource represented by the RequestDispatcher.

A servlet can call this method if it has not yet requested an OutputStream or a Writer from the response.

Note that the RequestDispatcher can change the request object before handing it to the target resource depending on the string that was given to getRequestDispatcher().

Parameters:
request - the original request
response - the response to which output should be written
Throws:
ServletException - can be thrown by the target resource
java.io.IOException - if an I/O-error occurs
java.lang.IllegalStateException - if getOutputStream or getWriter has already been called on the response
Since:
Servlet API 2.1

include

public void include(ServletRequest request,
                    ServletResponse response)
             throws ServletException,
                    java.io.IOException
Includes into the ServletResponse any output written by the resource represented by the RequestDispatcher.

Note that the target resource can only use the OutputStream or Writer that the original caller uses. It can not set any headers. Also note that any sessions should be started before calling include.

The RequestDispatcher will not alter the original request before handing it to the target resource.

Parameters:
request - the original request
response - the original response
Throws:
ServletException - can be thrown by the target resource
java.io.IOException - if an I/O-error occurs
Since:
Servlet API 2.1