Tiles与siteMesh页面布局管理

 

Tiles的使用
       Tiles 是apache推出的布局管理工具包。其原理和功能类似于jsp:include 和 <c:import >标签。如果多个页面中有多个公共的内容时,使用 Tiles来定义一个公有区域的模板,在其它页面中只需要简单引入就可以了。
       安装步骤:
1.       http://struts.apache.org/ 上下载 struts 。解压缩后将
a)         struts.jar
b)        commons-beanutils.jar
c)        commons-collections.jar
d)        commons-digester.jar
e)         commons-logging.jar
         放入包lib包中。
2.       在 web.xml中配置
< servlet >
            < servlet-name > Tiles Servlet </ servlet-name >
            < servlet-class >
                org.apache.struts.tiles.TilesServlet
            </ servlet-class >
            < init-param >
                < param-name > definitions-config </ param-name >
                < param-value > /WEB-INF/tiles.xml </ param-value >
            </ init-param >
         < load-on-startup > 2 </ load-on-startup >
  </ servlet >
3.       在web-inf/目录下新建 tiles.xml 文件
<! DOCTYPE tiles-definitions PUBLIC
   "-//Apache Software Foundation//DTD Tiles Configuration//EN"
   "http://jakarta.apache.org/struts/dtds/tiles-config.dtd" >
< tiles-definitions >
< definition name = "subview" path = "/pages/subview.jsp" >
    < put name = "jianshe" value = "jianshetest" ></ put >
</ definition >
</ tiles-definitions >
        定义布局
      
4.    subview.jsp 的代码:
<%@ page language = "java" contentType = "text/html; charset=UTF-8" pageEncoding = "ISO-8859-1" %>
<%@ taglib uri = "http://java.sun.com/jsf/core" prefix = "f" %>
<%@ taglib uri = "http://java.sun.com/jsf/html" prefix = "h" %>
<%@ taglib uri = "http://jakarta.apache.org/struts/tags-tiles" prefix = "tiles" %>
< f:subview id = "sub" >
  < tiles:importAttribute scope = "request" />
  < h:outputText value = "asfdasfdasfasfasfasf" ></ h:outputText >
  < h:outputText value = "#{jianshe}"></h:outputText>
</ f:subview >
 
5.    index.jsp 的代码
<%@ page language = "java" contentType = "text/html; charset=ISO-8859-1" pageEncoding = "ISO-8859-1" %>
<%@ taglib uri = "http://java.sun.com/jsf/core" prefix = "f" %>
<%@ taglib uri = "http://java.sun.com/jsf/html" prefix = "h" %>
<%@ taglib uri = "http://jakarta.apache.org/struts/tags-tiles" prefix = "tiles" %>
 
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
< html >
    < head >
       < title > Insert title here </ title >
    </ head >
    < body >
       < f:view >
    <%--
       <jsp:include flush="true" page="subview.jsp"></jsp:include>
    --%>
           < tiles:insert definition = "subview" flush = "false" ></ tiles:insert >
       </ f:view >
    </ body >
</ html >
注意:
1.       tils.xml中可以传给模板传参数:
< put name = "jianshe" value = "jianshetest" ></ put > 定义名为 jianshe 变量
subview.jsp 中引用为
< h:outputText value = "#{jianshe}"></h:outputText>
          在使用变量前需要加入
< tiles:importAttribute scope = "request" /> 来导入变量
    有关 Tiles 更深入的使用方法请参阅  http://tech.ccidnet.com/art/1110/20041125/181761_1.html
stieMesh是也是一种布局管理工具,原理是对输出结果过滤产生 符合统一布局的页面效果:
有关使用请参阅:

http://www.cjsdn.net/post/view?bid=29&id=178862 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值