包含指令可重用重複代碼(如頁首、頁尾、導航欄)。JSP 提供兩種包含方式:靜態包含與動態包含。
info.html
<h2><font color="red">info.html</font></h2>
info.jsp
<h2><font color="green"><%= "info.jsp" %></font></h2>
baohan.jsp(主頁)
<%@ page contentType="text/html" pageEncoding="GB2312" %>
<html><head><title>靜態包含操作</title></head><body>
<h1>靜態包含操作</h1>
<%@ include file="info.html" %>
<%@ include file="info.jsp" %>
</body></html>
執行後檢視原始碼可見:靜態包含在編譯階段直接將內容替換合併,類似變量替換。