It is often useful to include another Web resource, for example, banner content or copyright information, in the response returned from a Web component. To include another resource, invoke theinclude method of a RequestDispatcher object:
If the resource is static, the include method enables programmatic server-side includes. If the resource is a Web component, the effect of the method is to send the request to the included Web component, execute the Web component, and then include the result of the execution in the response from the containing servlet. An included Web component has access to the request object, but it is limited in what it can do with the response object:
It can write to the body of the response and commit a response.
It cannot set headers or call any method (for example, setCookie) that affects the headers of the response.
The banner for the Duke’s Bookstore application is generated by BannerServlet. Note that both the doGet and doPost methods are implemented because BannerServlet can be dispatched from either method in a calling servlet.