- 作者:zhaozj
- 发表时间:2020-12-23 10:52
- 来源:未知
1.在你的struts配置文件中加入下面的配置:<plug-in className="org.apache.struts.tiles.TilesPlugin" ><set-property property="definitions-config" value="/WEB-INF/tiles-def.xml" /><set-property property="definitions-parser-validate" value="true" /> </plug-in>2.生成tiles-def.xml文件:<xml version="1.0" encoding="ISO-8859-1" ><!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd">
<tiles-definitions> <definition name="base-definition" path="/layout.jsp"> <put name="sidebar" value="sidebar.jsp"/> <put name="header" value="header.jsp"/> <put name="content" value=""/> <put name="footer" value="footer.jsp"/> </definition>
<definition name="index-definition" extends="base-definition"> <put name="content" value="indexContent.jsp"/> </definition>
</tiles-definitions>
3.生成layout.jsp布局文件:<%@ page contentType="text/html; charset=UTF-8" %><%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%> <html> <head> <title>布局设计</title> </head> <body > <% One table lays out all of the content %> <table width="100%" height="100%"> <% Sidebar section %> <tr> <td width="150" valign="top" align="left" bgcolor="#CCFFCC"> <tiles:insert attribute="sidebar"/> </td> <% Main content section %> <td valign="top" height="100%" width="*"> <table width="100%" height="100%"> <tr> <% Header section %> <td height="15%"> <tiles:insert attribute="header"/> </td> <tr> <tr> <% Content section %> <td valign="top" height="*"> <tiles:insert attribute="content"/> </td> </tr> <tr> <% Footer section %> <td valign="bottom" height="15%"> <tiles:insert attribute="footer"/> </td> </tr> </table> </td> </tr> </table> </body> </html> 4.生成要使用的JSP文件sidebar.jsp,header.jsp,footer.jsp。
5.通过action-mappings配置你的tiles组件:<action-mappings><action path="/index" type="org.apache.struts.actions.ForwardAction" parameter="index-definition"></action></action-mappings>parameter参数的值,是你在tiles-def.xml文件里某个的define的name。