J2EE(04) 页面通用部分共用办法 jsp:include 使用

设计页面,头部,导航条,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>
]]>
这种方式是较老的方式,缺点是不能及时刷新,不能传递参数,因此,这个方法可以不要使用


2. 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>
]]>

可以传递参数:

<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>




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值