1.include指令
静态包含:被包含的文件需要和当前文件合并才能翻译成一个Servlet源文件(.java),即编译器包含,包含的是源代码。
date.jsp
<%@page import="java.util.Date"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <%= new Date().toString() %> </body> </html>
include.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <!-- 静态包含同一目录下的date.jsp --> 当前时间是:<%@include file="date.jsp"%> </body> </html>
访问include.jsp:http://localhost:8080/Javaweb01/jsp/include.jsp
【注意】生成一个.java文件和一个.class文件。
2.<jsp:include>
动态包含:被包含的文件是运行时才被包含的,而且只包含运行结果。
date.jsp
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%= new Date().toString() %>
</body>
</html>
include.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <!-- 动态包含同一目录下的date.jsp --> 当前时间是:<jsp:include page="date.jsp"></jsp:include> </body> </html>
访问include.jsp:http://localhost:8080/Javaweb01/jsp/include.jsp
扫描二维码关注公众号,回复:
1515929 查看本文章
【注意】生成两个.java文件和两个.class文件