j2ee: Request Dispatching [20/20] ![]() ![]() |
Often, when building a web application, you want to forward processing to another component. Or, you might want to include the processing of another component in the current response.
In order to do this using the Servlet API, we need to use a Request Dispatcher.
This is retrieved from the ServletContext
.
public RequestDispatcher getRequestDispatcher(String path)
The RequestDispatcher
is created based on the path used
to obtain it (must begin with a "/"). This is a context relative resource.
public void forward(ServletRequest request, ServletResponse response) public void include(ServletRequest request, ServletResponse response)
Forwarding is usually used when one servlet (or JSP) processes the request, and the other processes the response. Include is a resource for doing server side includes (allowing other servlets to do part of the request handling or response generation
We need to understand Request Dispatching in order to integrate Servlets and JSPs properly.