JSp的动作标识<jsp:include>用于向当前页中包含其它的文件。被包含的文件可以是动态文件,也可以是静态文件。
动作标识的语法如下:
<jsp:include page="url" flush="false|true"/>
//或
<jsp:include page="url" flush="false|true">
子动作标识<jsp:param>
</jsp:include>
page:用于指定被包含文件的相对路径。
flush:可选属性,用于设置是否刷新缓冲区。
子动作标识<jsp:param>:用于向被包含的动态网页中传递参数。
在应用<jsp:include>标识进行文件包含时,为了使整个页面的层次结构不发生冲突,建议在被包含页面中将<html>,<body>等标记删除。
下面是案例:
建立一个top.jsp文件,导航栏,代码如下:
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<img src="image/1.png">
建立一个copy.jsp文件,尾端,代码如下:
<%@ page pageEncoding="GB18030"%>
<%String copyright=" All Copyright ©出差从多角度"; %>
<table width="778" height="61" border="0" cellpadding="0"
cellspacing="0" background="image/3.png">
<tr><td><%=copyright %></td>
</tr>
</table>
建立一个inde.jsp文件,中间部分,代码如下:
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!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=GB18030">
<title>Insert title here</title>
</head>
<body style="margin:0px;">
<jsp:include page="top.jsp"/>
<table width="1778" height="561" border="0" cellpadding="0"
cellspacing="0" background="image/2.png">
</table>
<jsp:include page="copy.jsp"/>
</body>
</html>
运行效果如下: