有两种方法可以创建Tiles定义并为应用程序指定他们的属性。如下: 方法 1:基于JSP的定义和属性1. 建立工程S_Tiles,并在在struts-config.xml中添加 <!-- Tiles定义--> <plug-in className="org.apache.struts.tiles.TilesPlugin"> <set-property property="definitions-config" value ="/WEB-INF/tiles-defs.xml,/WEB-INF/tiles-defs-baseinfo.xml" /> </plug-in> 2. 创建 header.jsp footer.jsp menu.jsp body.jsp,代码如下: <html:html lang="true"> <body> <table align="center"> <tr> <td align="center"> <p><font color="blue">页头(This is header)</font> </p> </td> </tr> </table> </body> </html:html> ########################################################## <html:html > <body> <table align="center"> <tr> <td align="center"> <p><font color="blue">页脚(This is the footer)</font> </p> </td> </tr> </table> </body> </html:html> ############################################################# <html:html> <body> <table align="center"> <tr> <td align="center"> <p><font color="red">导航菜单(Here is the menu)</font> </p> </td> </tr> </table> </body> </html:html> ############################################################# <html:html> <body> <table align="center"> <tr> <td align="center"> <p><font color="red">页体(Here is the body)</font> </p> </td> </tr> </table> </body> </html:html> 3. 创建页面布局文件layout.jsp,代码如下: <%...@ page language="java" pageEncoding="gb2312"%> <%...@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%> <%...@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%> <%...@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%> <%...@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html:html lang="true"> <body> <table align="center"> <tr> <td colspan="2"> <tiles:insert attribute="header" /> </td> </tr> <tr> <td width="15%"> <tiles:insert attribute="menu" /> </td> <td> <tiles:insert attribute="body" /> </td> </tr> <tr> <td colspan="2"> <tiles:insert attribute="footer" /> </td> </tr> </table> </body> </html:html> 4. 最后创建引用 布局页面 layout.jsp 的页面 layoutResult.jsp <%...@ page language="java" pageEncoding="gb2312"%> <%...@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%> <%...@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%> <%...@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%> <%...@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%> <tiles:insert page="/tiles/layout.jsp" flush="true"> <tiles:put name="title" value="Tiles" /> <tiles:put name="header" value="header.jsp" /> <tiles:put name="footer" value="footer.jsp" /> <tiles:put name="menu" value="menu.jsp" /> <tiles:put name="body" value="body.jsp" /> </tiles:insert> 6.最后项目结构如图: 5.访问layoutResult.jsp,便看到结果