JSP指令元素include指令的使用实例
JSP指令元素include指令的使用实例
有两个文件,文件ch03_4_include1.jsp的功能是显示“Hello World!”,而文件ch03_4_include2.jsp,首先输出(服务器)系统的日期和时间,然后通过include指令将ch03_4_include1.jsp文件包含进来。在网页地址中输入ch03_4_include2.jsp页面地址,其运行结果如图:
(1)ch03_4_include1.jsp代码:
<%@page language="java" pageEncoding="UTF-8"%>
<html>
<head><title>被include包含的文件</title></head>
<body><h1>Hello World!</h1></body>
</html>
(2)ch03_4_include2.jsp代码:
<%@page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>include指令实例</title>
</head>
<body>
<center>
现在的日期和时间是:<%=new Date()%>
<hr>
<%@include file="ch03_4_include1.jsp"%>
</center>
</body>
</html>
注意:这两个文件,在运行前(部署时),经编译合成一个*.class文件(这种性质称为静态插入),运行时只执行这个class文件。