Chinaunix首页 | 论坛 | 博客
  • 博客访问: 738501
  • 博文数量: 60
  • 博客积分: 10010
  • 博客等级: 上将
  • 技术积分: 2090
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-27 12:33
文章分类

全部博文(60)

文章存档

2008年(60)

我的朋友

分类: Java

2008-04-21 13:02:54

Tiles标签库的tiles:insert标签和JSP include指令具有相同的功能,也能把其他的JSP页面插入到当前页面中。例如,以下两条语句的作用是相同的:


    标签的page属性指定被插入的JSP文件,flush属性的可选值包括true和false,当flush属性为true,表示在执行插入操作之前,先调用当前页面的输出流的flush()方法。

    提示:本节介绍的tilestaglibs应用的源程序位于配套光盘的sourcecode/tilestaglibs/version3/tilestaglibs目录下。如果要在Tomcat上发布这个应用,只要把version3目录下的整个tilestaglibs子目录拷贝到/webapps目录下即可。

    以下是在tilestaglibs应用中使用标签的步骤。

    (1)安装Tiles标签库所需的文件
    在Struts的下载软件中包含了运行Tiles标签库所需的文件。如果Web应用中使用了Tiles标签库,以下文件必须位于WEB-INF/lib目录中:
    ·struts.jar
    ·commons-digester.jar
    ·commons-beanutils.jar
    ·commons-collections.jar
    ·commons-logging.jar

    此外,应该把Tiles标签库的定义文件struts-tiles.tld拷贝到WEB-INF目录下。

    (2)在web.xml文件中配置如下元素:


    /WEB-INF/struts-tiles.tld
    /WEB-INF/struts-tiles.tld

    (3)创建index.jsp和product.jsp文件
    修改16.2节的例程16-8(index.jsp)和例程16-9(product.jsp),在index.jsp和product.jsp文件的开头,通过%@ taglib指令引入Tiles标签库,然后把源代码中的JSP include指令改为tiles:insert标签。例程16-10和例程16-11分别为修改后的index.jsp和product.jsp文件。

    例程16-10 ndex.jsp

<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>

   
      TilesTaglibs Sample
   
   
      <%-- One table lays out all of the content for this page --%>
      
            <%-- Sidebar section --%>
            
            <%-- Main content section --%>
            
<%-- Header section --%> <%-- Content section --%> <%-- Footer section --%>

    例程16-11 product.jsp

<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>

   
      TilesTaglibs Sample
   
   
      <%-- One table lays out all of the content for this page --%>
      
            <%-- Sidebar section --%>
            
            <%-- Main content section --%>
            
<%-- Header section --%> <%-- Content section --%> <%-- Footer section --%>

    从例程16-10和例程16-11可以看出,用tiles:insert标签取代JSP include指令来创建复合式页面,代码仅有稍微的差别,两者的利弊也很相似。单纯使用tiles:insert标签来创建复合式页面,还没有充分发挥Tiles框架的优势。

阅读(2327) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~