include指令用于在当前JSP页面中指令所在位置将指令指定的资源内容包含进来,被包含的资源可以是JSP文件,HMTL文件,文本文件,Inc文件等。
JSP解析器一律将其作为JSP文件对待,转化为Servlet时进行语法检查。
include指令包含是静态的。
include指令的格式为:<% include file="filename"%>
filename为要包含的资源的路径和文件名
- include使用实例
- includeDir.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>JSP 基本语法</title> </head> <body> <%@ include file="/jsp123/head.inc" %> <h1>include指令示例页面</h1> <%@include file="/jsp123/foot.txt"%> </body> </html>
- head.inc
<%@ page contentType="text/html;charset=UTF-8" %> <h1>JSP Web应用程序例程</h1> <hr>
- foot.txt
<%@ page contentType="text/html;charset=UTF-8" %> <hr> © 临沂师范学院信息学院 杨占胜 2009