JSP Includes
September 4th, 2009
No comments
I occasionally dabble with Java Server Pages (JSP) and in this I often find myself wanting to include the contents of other pages. There might be other ways to do this but generally I use one of two methods depending on the type of page I need to include.
- Compile-Time include: Contents of the included file are inserted into the JSP page before it is compiled into a servlet. I normally use compile-time includes with pages that tend to have static content.
<%@ include file=”includeFile.html” %>
- Run-Time include: Results of the included page are inserted into the JSP page when the servlet engine reaches the include directive.
<jsp:include page=”includePage.jsp” flush=”true”/>
Using flush=”true” tell the servlet engine to flush the output buffer before including the file. This helps to make sure that you don’t get an old version of the included page. One reason to include a page at run-time is to be able to pass parameters to it like this:
<jsp:include page=”salary.jsp” flush=”true”>
<jsp: param name=”employeeId” value=”1022″/>
</jsp:include>


