这里使用的是Tiles 3的版本,我们首先搭建一个简单的例子来理解一下Tiles。
一、首先我们加载所需要的jar包,这里我们使用Maven来帮助我们来获取jar包,<!-- Tiles -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>3.0.5</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-servlet</artifactId>
<version>3.0.5</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>3.0.5</version>
</dependency>
然后在web.xml中添加Tiles的相关配置
<!-- Tiles -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>3.0.5</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-servlet</artifactId>
<version>3.0.5</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>3.0.5</version>
</dependency>
<strong><listener>
<listener-class>org.apache.tiles.extras.complete.CompleteAutoloadTilesListener</listener-class>
</listener></strong>
在WEB-INF添加 tiles-defs.xml文件:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
"http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<!-- Definitions for Tiles documentation -->
<tiles-definitions>
<definition name="tiles.base.definition" template="/tiles/layout/layout.jsp">
<put-attribute name="header" value="/tiles/public/header.jsp" />
<put-attribute name="menu" value="/tiles/public/menu.jsp" />
<put-attribute name="footer" value="/tiles/public/footer.jsp" />
</definition>
</tiles-definitions>
配置完成
覆盖:
<definition name="tiles.override.definition" extends="tiles.base.definition">
<put-attribute name="footer" value="Copy Right <a href='http://blog.csdn.net/u014715974'>Manjusaka</a>"></put-attribute>
</definition>
这样页面调用 tiles.override.definition 的时候就可以达到覆盖footer的效果