d动态包含与静态包含的最大区别是
静态包含:<%@ include file = "文件名.jsp"%>,在<body>的标签外定义。在没有编译的时候,两个java文件都已经包含起来了(合并成一个)。
动态包含:<%jsp:include page= "/文件名.jsp"> <jsp:include>,在<body>标签内定义。在编译之前永远是两个java文件。
静态包含实例代码:先定义一个hel.jsp
<%--
Created by IntelliJ IDEA.
User: sunyubin
Date: 2018/9/11
Time: 下午8:25
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%
String name ="sunyubin";
%>
</body>
</html>
再定义一个lo.jsp文件:
<%--
Created by IntelliJ IDEA.
User: sunyubin
Date: 2018/9/11
Time: 下午8:27
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/hel.jsp" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1><%=name %><h1/>
</body>
</html>
先运行hel.jsp,再运行lo.jsp。
接下来,再演示一下动态演示过程。
hel.jsp没有变化;
变化的只是lo.jsp
<%--
Created by IntelliJ IDEA.
User: sunyubin
Date: 2018/9/11
Time: 下午8:27
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
html>
<head>
<title>Title</title>
</head>
<body>
<jsp: page include = "/hel.jsp"%> </jsp:> <h1><%=name %><h1/> </body>
</html>