本文主要是介绍strtus之Titles框架应用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Tiles框架建立在JSP的include指令的基础上,但它提供了比JSP的include指令更强大的功能。
Tiles框架具有如下特性:
- 创建可重用的模板
- 动态构建和装载页面
- 定义可重用的Tiles组件
- 支持国际化
Tiles框架包含以下内容:
- Tiles标签库
- Tiles组件的配置文件
- TilesPlugIn插件
Tiles标签库的<tiles:insert>标签和JSP include指令具有相同的功能,也能把其他的JSP
页面插入到当前页面中。例如,以下两条语句的作用是相同的:
<jsp:include page="indexContent.jsp"/>
<tiles:insert page="indexContent.jsp" flush="true"/>
<tiles:insert>标签的page 属性指定被插入的JSP 文件;flush属性的可选值包括true 和
false。当flush的属性值为true时,表示在执行插入操作之前,先调用当前页面的输出流的
flush()方法。
开发步骤
(1)安装Tiles标签库所需的文件。
以下文件必须位于WEB-INF/lib 目录中:
l struts.jar
l commons-digester.jar
l commons-beanutils.jar
l commons-collections.jar
l commons-logging.jar
此外,应该把Tiles标签库的定义文件struts-tiles.tld拷贝到WEB-INF目录下。
(2)在web.xml文件中配置如下<taglib>元素:
<taglib>
<taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
</taglib>
(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>标签.
index.jsp
<%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %> <html> <head> <title>TilesTaglibs Sample</title> </head> <body > <%-- One table lays out all of the content for this page --%> <table width="100%" height="100%"> <tr> <%-- Sidebar section --%> <td width="150" valign="top" align="left" bgcolor="#CCFFCC"> <tiles:insert page="sidebar.jsp" flush="true"/> </td> <%-- Main content section --%> <td height="100%" width="*"> <table width="100%" height="100%"> <tr> <%-- Header section --%> <td valign="top" height="15%"> <tiles:insert page="header.jsp" flush="true"/> </td> <tr> <tr> <%-- Content section --%> | |
例程16-11 product.jsp <%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %> <html> <head> <title>TilesTaglibs Sample</title> </head> <body > <%-- One table lays out all of the content for this page --%> <table width="100%" height="100%"> <tr> <%-- Sidebar section --%> <td width="150" valign="top" align="left" bgcolor="#CCFFCC"> <tiles:insert page="sidebar.jsp" flush="true"/> </td> <%-- Main content section --%> <td height="100%" width="*"> <table width="100%" height="100%"> <tr> <%-- Header section --%> <td valign="top" height="15%"> <tiles:insert page="header.jsp" flush="true"/> </td> <tr> <tr> <%-- Content section --%> <td val |
这篇关于strtus之Titles框架应用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!