前提物质条件: 1.Struts Framework; 2.struts-tiles.tld
四. mainlayout.jsp内容
五.tiles的调用
index.jsp内容
或者(无需tiles-defs.xml)
一. web.xml配置
<
servlet
>
< servlet-name >action </ servlet-name >
< servlet-class >org.apache.struts.action.ActionServlet </ servlet-class >
< init-param >
< param-name >config </ param-name >
< param-value >/WEB-INF/struts-confg.xml </ param-value >
</ init-param >
<init-param>
<param-name>definitions-config</param-name>
<param-value>/WEB-INF/tiles-defs.xml</param-value>
</init-param>
< load-on-startup >1 </ load-on-startup >
</ servlet >
...
<taglib>
<taglib-uri>/tags/struts-tiles</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-tiles.tld</taglib-location>
</taglib>
< servlet-name >action </ servlet-name >
< servlet-class >org.apache.struts.action.ActionServlet </ servlet-class >
< init-param >
< param-name >config </ param-name >
< param-value >/WEB-INF/struts-confg.xml </ param-value >
</ init-param >
<init-param>
<param-name>definitions-config</param-name>
<param-value>/WEB-INF/tiles-defs.xml</param-value>
</init-param>
< load-on-startup >1 </ load-on-startup >
</ servlet >
...
<taglib>
<taglib-uri>/tags/struts-tiles</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-tiles.tld</taglib-location>
</taglib>
二. struts-confg.xml配置
<
plug-in
className
="org.apache.struts.tiles.TilesPlugin"
>
< set-property property ="definitions-config" value ="/WEB-INF/tiles-defs.xml" />
</ plug-in >
< set-property property ="definitions-config" value ="/WEB-INF/tiles-defs.xml" />
</ plug-in >
三. 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 ="site.mainLayout" path ="/mainlayout.jsp" >
< put name ="header" value ="/header.html" />
< put name ="body" value ="/logon.jsp" />
< put name ="footer" value ="/footer.html" />
</ definition >
</ tiles-definitions >
<!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 ="site.mainLayout" path ="/mainlayout.jsp" >
< put name ="header" value ="/header.html" />
< put name ="body" value ="/logon.jsp" />
< put name ="footer" value ="/footer.html" />
</ definition >
</ tiles-definitions >
四. mainlayout.jsp内容
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="/tags/struts-tiles" prefix="tiles" %>
< html >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=UTF-8" />
< title >tiles </ title >
</ head >
< body >
< tiles:insert attribute ="header" />
< tiles:insert attribute ="body" />
< tiles:insert attribute ="footer" />
</ body >
</ html >
<%@ taglib uri="/tags/struts-tiles" prefix="tiles" %>
< html >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=UTF-8" />
< title >tiles </ title >
</ head >
< body >
< tiles:insert attribute ="header" />
< tiles:insert attribute ="body" />
< tiles:insert attribute ="footer" />
</ body >
</ html >
五.tiles的调用
index.jsp内容
<
%@ page
contentType
="text/html; charset=UTF-8"%
>
< %@ taglib uri ="/tags/struts-tiles" prefix ="tiles" % >
< tiles:insert definition ="site.mainLayout" flush ="true" />
< %@ taglib uri ="/tags/struts-tiles" prefix ="tiles" % >
< tiles:insert definition ="site.mainLayout" flush ="true" />
<
%@ taglib
uri
="http://struts.apache.org/tags-tiles"
prefix
="tiles" %
>
< tiles:insert template ="mainlayout.jsp" >
< tiles:put name ="title" value ="This is the title." />
< tiles:put name ="header" value ="header.jsp" />
< tiles:put name ="body" value ="body.jsp" />
</tiles:insert>
< tiles:insert template ="mainlayout.jsp" >
< tiles:put name ="title" value ="This is the title." />
< tiles:put name ="header" value ="header.jsp" />
< tiles:put name ="body" value ="body.jsp" />
</tiles:insert>
本文转自 Icansoft 51CTO博客,原文链接:
http://blog.51cto.com/android/118611