设计页面,头部,导航条,foot,所有页面基本一致,不要在每个页面进行重复设计,而采用将通用部分存为一个一个的jsp页面,使用的页面只需要引用的模式
引入jsp页面有2种方式
1. <%@ include file="included.html" %> 这种称为JSP include 伪指令
<![CDATA[ <%@ page language="java" contentType="text/html" %> <html> <head> <title>JSP include element test</title> </head> <body> This content is statically in the main JSP file.<br /> <%@ include file="included.html" %> </body> </html> ]]> |
<![CDATA[ <%@ page language="java" contentType="text/html" %> <html> <head> <title>JSP include element test</title> </head> <body> This content is statically in the main JSP file.<br /> <%@ include file="included.html" %> </body> </html> ]]> |
可以传递参数:
<jsp:include page="header.jsp" flush="true"> <jsp:param name="pageTitle" value="newInstance.com"/> <jsp:param name="pageSlogan" value=" " /> </jsp:include>
header.jsp里面可以直接取出参数:
<%=request.getParameter("pageTitle") %>
引用页面需要注意的:
被应用的页面,不能够包含html body等标记,可以引用css
举例页面:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<link href="css/header.css" rel="stylesheet" type="text/css" />
<div id="maindiv">
<%=request.getParameter("pageTitle") %>
</div>