需要jar包:
commons-digester-2.0.jar
struts2-tiles-plugin-.jar
tiles-api-2.0-20070207.130156-4.jar
tiles-core-2.0-20070207.130156-4.jar
commons-beanutils-1.6.jar
commons-logging.jar
freemarker.jar
ognl-.jar
struts2-core-.jar
xwork-.jar
commons-collections-.jar
WEB-INF文件下需要:tiles.dtd
Web.xml文件配置如下 :
<!-- 创建Titles工厂 -->
<context-param>
<param-name>org.apache.tiles.CONTAINER_FACTORY</param-name>
<param-value>
org.apache.struts2.tiles.StrutsTilesContainerFactory
</param-value>
</context-param>
<!-- 全局变量,指定tiles.xml的路径 -->
<context-param>
<param-name>
org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
</param-name>
<param-value>/WEB-INF/tiles.xml</param-value>
</context-param>
<!-- tiles监听器(一) 有两种监听器 -->
<listener>
<listener-class>
org.apache.tiles.listener.TilesListener
</listener-class>
</listener>
<!-- tiles监听器(二) 二选一 -->
<!--
<listener>
<listener-class>
org.apache.tiles.listener.TilesListener
</listener-class>
</listener>
-->
<!-- struts配置 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Titles.xml配置文件如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://jakarta.apache.org/struts/dtds/tiles-config.dtd">
<tiles-definitions>
<!-- 定议一个模版 -->
<definition name="login.index" template="log.jsp">
<!-- 设置各模块的内容 -->
<put name="top" value="/tiles/top.jsp"></put>
<put name="center" value="/tiles/center.jsp"></put>
<put name="bottom" value="/tiles/bottom.jsp"></put>
</definition>
</tiles-definitions>
Struts.xml配置文件如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<!-- 包空间 注意其中的extends="tiles-default" -->
<package name="default" extends="tiles-default">
<!-- 全局results -->
<global-results>
<result name="success" type="tiles">login.index</result>
</global-results>
<!-- 请求 -->
<action name="login" class="com.Test"></action>
</package>
</struts>