1.在struts-config.xml中插入下文件:
<plug-in className="org.apache.struts.tiles.TilesPlugin"> <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml"/> <set-property property="moduleAware" value="false"/> </plug-in> 2.web.xml文件加入标签库的应用: <jsp-config> <taglib> <taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri> <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location> </taglib> </jsp-config> 3.在页面上使用<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>引入tiles标签。 4.定义tiles-defs.xml文件: <?xml version="1.0" encoding="UTF-8"?> <!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="index-definition" path="/MyJsp2.jsp"> </definition> </tiles-definitions> 5.编写页面框架: <%@ page language="java" pageEncoding="GB2312"%> <%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title><tiles:getAsString name="title"/></title>
<meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page">
</head> <body text="#333333" bgcolor="#ffffff" leftmargin="2" topmargin="2"marginwidth="0" marginheight="0"> <div align="center"> <tiles:insert attribute="top" /> <table border="0" width="100%" height="90%" cellspacing="0" cellpadding="0"> <tr> <td width="15%" height="80%" valign="top" align="left" > <tiles:insert attribute="left" /> </td> <td width="85%" align="center" height="50%" valign="top"> <tiles:insert attribute="body"/> </td> </tr> </table> <tiles:insert attribute="bottom"/> </div> </body> </html>
6。在web.xml配置<welcome-file-list>为包含以下内容的jsp页面welcome.jsp: <tiles:insert definition="baseinfo_template" flush="true"/>
|
|