jsp代码
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%@include file="staticTest.jsp"%>
<h2>静态包含</h2>
<hr>
<jsp:include page="dynamicTest.jsp"/>
<h2>动态包含</h2>
</body>
</html>
静态包含的语法<%@include file="xxx.jsp"%>
动态包含的语法<jsp:include page="xxx.jsp"/>
有什么区别呢?
我们先来看看访问效果
第一次访问之后才会生成.java文件
我们知道,所有jsp文件其实最后都会生成servlet,就是.java
文件,我们找到tomcat的工作目录work中,找到.java文件,来查看一下
我们先看目录,发现有两个文件
再看文件
out.write("\r\n");
out.write("\r\n");
out.write("<html>\r\n");
out.write("<head>\r\n");
out.write(" <title>Title</title>\r\n");
out.write("</head>\r\n");
out.write("<body>\r\n");
out.write("\r\n");
out.write("\r\n");
out.write("\r\n");
out.write("<html>\r\n");
out.write("<head>\r\n");
out.write(" <title>hhh\r\n");
out.write(" </title>\r\n");
out.write("</head>\r\n");
out.write("<body>\r\n");
out.write("<h1>静态测试</h1>\r\n");
out.write("</body>\r\n");
out.write("</html>\r\n");
out.write("\r\n");
out.write("<h2>静态包含</h2>\r\n");
out.write("\r\n");
out.write("\r\n");
out.write("<hr>\r\n");
out.write("\r\n");
org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, "dynamicTest.jsp", out, false);
out.write("\r\n");
out.write("\r\n");
out.write("<h2>动态包含</h2>\r\n");
out.write("\r\n");
out.write("</body>\r\n");
out.write("</html>\r\n");
说明静态和动态的区别:
静态就是直接合并成一个,动态是导入但不合并