1.在WEB-INF/lib下加入所需的jar包
commons-digester-1.6.jar,
tiles-core-2.0-20070207.130156-4.jar,
tiles-api-2.0-20070207.130156-4.jar,
struts2-tiles-plugin-2.0.6.jar,
struts2-core-2.0.6.jar
xwork-2.0.1.jar,
2. 以下内容添加到web.xml
<listener> <listener-class> org.apache.tiles.listener.TilesListener </listener-class> </listener>
3.在WEB-INF下添加和tiles.tld和tiles.xml文件,其中tiles.tld内容为tiles-core-2.0-20070207.130156-4.jar包中META_INF/tiles-core.tld的内容。
tiles.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="myapp.homepage" template="layout.jsp"> <put name="title" value="Tiles tutorial homepage" /> <put name="header" value="/tiles/header.jsp" /> <put name="menu" value="/tiles/menu.jsp" /> <put name="body" value="/tiles/cBody.jsp" /> <put name="footer" value="/tiles/footer.jsp" /> </definition> </tiles-definitions>
4.struts.xml 为:
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="default" extends="tiles-default"> <action name="go" class="com.action.MyAction"> <!--result name="success">/next.jsp</result--> <result name="success" type="tiles">myapp.homepage</result> </action> </package> </struts>
红色部分根据自己项目定。注意extends="tiles-default"
另外也可以这样配置:
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
<package name="struts-shop" extends="struts-default,json-default"> <result-types> <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" /> </result-types> </package>