系列首篇,介紹 JSP Include 機制,將靜態頁首、頁腳納入網站頁面。
專業網站共用頁首、頁尾、導航欄,僅主內容區變化。早期用框架實現,但跨瀏覽器顯示不一、外部連結嵌套問題多。伺服器端 Include (SSI) 是替代方案,但非標準、依賴 Web 伺服器。
<%@ include file="header.jsp" %>
<%@ include file="navigation.jsp" %>
<%@ include file="footer.jsp" %>
編譯期靜態合併,效能佳,適合靜態內容。動態內容需用 <jsp:include>(下文介紹)。
將 test-ssi.shtml 與 included.html 存放於同目錄,驗證 SSI 與 JSP Include 差異。