在你的struts配置文件struts
config
xml中加入下面的配置
<plugin className=orgapachestrutstilesTilesPlugin >
<setproperty property=definitionsconfig value=/WEBINF/tilesdefxml />
<setproperty property=definitionsparservalidate value=true />
</plugin>
生成tilesdefxml文件
<?xml version= encoding=ISO ?>
<!DOCTYPE tilesdefinitions PUBLIC
//Apache Software Foundation//DTD Tiles Configuration //EN
/struts/dtds/tilesconfig__dtd>
<tilesdefinitions>
<definition name=basedefinition path=/layoutjsp>
<put name=sidebar value=sidebarjsp/>
<put name=header value=headerjsp/>
<put name=content value=/>
<put name=footer value=footerjsp/>
</definition>
<definition name=indexdefinition extends=basedefinition>
<put name=content value=indexContentjsp/>
</definition>
</tilesdefinitions>
生成layoutjsp布局文件
<%@ page contentType=text/html; charset=GBK %>
<%@ taglib uri=/tags/strutstiles prefix=tiles%>
<html>
<head> <title>布局设计</title> </head>
<body >
<table width=% height=%>
<tr>
<td width= valign=top align=left bgcolor=#CCFFCC>
<tiles:insert attribute=sidebar/>
</td>
<td valign=top height=% width=*>
<table width=% height=%>
<tr> <td height=%> <tiles:insert attribute=header/> </td> </tr>
<tr> <td valign=top height=*> <tiles:insert attribute=content/> </td></tr>
<tr> <td valign=bottom height=%><tiles:insert attribute=footer/></td></tr>
</table>
</td>
</tr>
</table>
</body> </html>
生成要使用的JSP文件sidebarjspheaderjspfooterjsp
通过actionmappings配置你的tiles组件
<actionmappings>
<action path=/index type=orgapachestrutsactionsForwardAction
parameter=indexdefinition>
</action>
</actionmappings>
parameter参数的值是你在tilesdefxml文件里某个的define的name
别忘了在webxml中加入
<taglib>
<tagliburi>/tags/strutstiles</tagliburi>
<tagliblocation>/WEBINF/strutstilestld</tagliblocation>
</taglib>
同时还要保证你使用的是struts 版本
现在就可以动手为你的项目加入tiles应用了
完成以上步骤完成Tomcate部署并启动通过:/strutsTiles/indexdo可以看到效果
运行下面两个文件是同样的效果
indexjsp
<%@ page contentType=text/html; charset=gb %>
<%@ taglib uri=/tags/strutstiles prefix=tiles %>
使用逻辑名
<tiles:insert definition=indexdefinition/>
indexjsp
<%@ page contentType=text/html; charset=gb %>
<%@ taglib uri=/tags/strutstiles prefix=tiles %>
<tiles:insert page=layoutjsp flush=true>
<tiles:put name=sidebar value=sidebarjsp/>
<tiles:put name=header value=headerjsp/>
<tiles:put name=content value=indexContentjsp/>
<tiles:put name=footer value=footerjsp/>
</tiles:insert>