See http://java-frog.iteye.com/blog/246449
Foreign Documents: http://onjava.com/pub/a/onjava/excerpt/progjakstruts_14/index3.html
1. Add the following configuration to your struts configuration file struts-config.xml:
<Plug-in classname = "org. Apache. Struts. Tiles. tilesplugin">
<Set-Property = "definitions-config" value = "/WEB-INF/tiles-def.xml"/>
<Set-Property = "definitions-parser-validate" value = "true"/>
</Plug-in>
2. Generate the tiles-def.xml file:
<? 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. Generate the layout. jsp layout file:
<% @ Page contenttype = "text/html; charset = GBK" %>
<% @ Taglib uri = "/tags/Struts-tiles" prefix = "tiles" %>
<HTML>
<Head> <title> layout design </title> <Body>
<Table width = "100%" Height = "100%">
<Tr>
& Lt; TD width = "150" valign = "TOP" align = "Left" bgcolor = "# ccffcc" & gt;
<Tiles: insert attribute = "sidebar"/>
</TD>
<TD valign = "TOP" Height = "100%" width = "*">
<Table width = "100%" Height = "100%">
<Tr> <TD Height = "15%"> <tiles: insert attribute = "Header"/> </TD> </tr>
<Tr> <TD valign = "TOP" Height = "*"> <tiles: insert attribute = "content"/> </TD> </tr>
<Tr> <TD valign = "bottom" Height = "15%"> <tiles: insert attribute = "footer"/> </TD> </tr>
</Table>
</TD>
</Tr>
</Table>
</Body>
4. generate the desired JSP file sidebar. jsp, header. jsp, and footer. jsp.
5. Configure your tiles component through action-mappings:
<Action-mappings>
<Action Path = "/Index" type = "org. Apache. Struts. Actions. forwardaction"
Parameter = "index-definition">
</Action>
</Action-mappings>
The value of the parameter is your define name in a tiles-def.xml file.
6. Don't forget to add it to Web. xml.
<Taglib>
<Taglib-Uri>/tags/Struts-tiles </taglib-Uri>
<Taglib-location>/WEB-INF/struts-tiles.tld </taglib-location>
</Taglib>
Make sure that you are using Struts 1.1.
Now you can add tiles applications to your project.
Complete the preceding steps to deploy and start the replicate service by using http: // 127.0.0.1: 8080/strutstiles/index. Do
You can see the effect.
Running the following two files has the same effect:
1. index1.jsp
<% @ Page contenttype = "text/html; charset = gb2312" %>
<% @ Taglib uri = "/tags/Struts-tiles" prefix = "tiles" %>
Use logical name
<Tiles: insert definition = "index-definition"/>
2. index. jsp
<% @ page contenttype = "text/html; charset = gb2312 "%>
<% @ taglib uri ="/tags/Struts-tiles "prefix =" tiles "%>