15.3. Including Static or Dynamic Content

If a servlet uses the forward method of RequestDispatcher, it cannot actually send any output to the client—it must leave that entirely to the destination page. If the servlet wants to generate some of the content itself but use a JSP page or static HTML document for other parts of the result, the servlet can use the include method of RequestDispatcher instead. The process is very similar to that for forwarding requests: call the getRequestDispatcher method of ServletContext with an address relative to the server root, then call include with the HttpServletRequest and HttpServletResponse. The two differences when include is used are that you can send content to the browser before making the call and that ...

Get Core Servlets and JavaServer Pages™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.