Show TOC

Including RequestsLocate this document in the navigation structure

Use

Use the include() method of the RequestDispatcher object to include the output of another servlet or JSP page in the response of the current servlet.

Process
  1. The servlet that uses the include() method passes the request to the other Web component.

  2. The Web component processes the request and generates output.

  3. This output is then returned to the initial servlet and included in the response.

The included Web component has access to the request object that is passes to the initial servlet. As far as the response object of the initial servlet is concerned, the included component can write to the response body but cannot commit the response. However, it is not allowed to change any header fields of the response.

Sample Code
               RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/SAPbanner");
    if (dispatcher != null)
        dispatcher.include(request, response);