1、将指定的JSP程序或者HTML文件包含进来
2、格式:<%@ include file = "fileURL"%> include中只有一个file属性
3、JSP Engine会在JSP程序的转换时期先把file属性设定的文件包含进来,然后开始执行转换及编译的工作
4、限制:
不能向firlURL中传递参数:例如:不能abc.jsp?user=aaa
代码示例
TestBar.jsp
- <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
- <html>
- <head>
- <title>My JSP 'TestBar.jsp' starting page</title>
- </head>
- <body>
- This is my JSP page. <br>
- <%@ include file = "title.jsp"%>
- <br>
- The jsp is in this JSP page!!
- </body>
- </html>
title.jsp
- <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
- <html>
- <head>
- <title>My JSP 'title.jsp' starting page</title>
- </head>
- <body>Hi:
- <%
- out.println(request.getParameter("test"));
- %>
- </body>
- </html>
运行TestBar.jsp时(没有传参数)的结果:
- This is my JSP page.
- Hi: null
- The jsp is in this JSP page!!
运行TestBar.jsp时(传参数:TestBar.jsp?test=abcde)的结果:
- This is my JSP page.
- Hi: abcde
- The jsp is in this JSP page!!