1, CreateWEB Project
2, DefineTiles. xml
The content is as follows::
<? XML
Version = "1.0" encoding = "UTF-8"
Standalone = "no"?>
<! Doctype tiles-Definitions System
"C:/javademo/dbdemo/userinfoweb/webroot/WEB-INF/tiles-config_2_1.dtd">
<Tiles-Definitions>
<Definition
Name = "MyApp. Homepage" template = "/tiles/layout. jsp">
<Put-attribute name = "title"
Value = "tiles tutorial Homepage"/>
<Put-attribute
Name = "Header" value = "/tiles/header. jsp"/>
<Put-attribute name = "menu"
Value = "/tiles/menu. jsp"/>
<Put-attribute name = "body"
Value = "/tiles/cbody. jsp"/>
<Put-attribute
Name = "footer" value = "/tiles/footer. jsp"/>
</Definition>
<Definition name = "Index"
Extends = "MyApp. Homepage">
<Put-attribute
Name = "body" value = "/content/indexcontent. jsp"/>
</Definition>
<Definition name = "list"
Extends = "MyApp. Homepage">
<Put-attribute
Name = "body" value = "/content/listcontent. jsp"/>
</Definition>
</Tiles-Definitions>
Note the red mark:If you cannot connect to the Internet, you can use the localDTDVerify thatVerify tiles-config_2_1.dtd
3, Set the page layout
TilesMyApp. homepage in is the default Template Name, and its layout isLayout. jspPage Control.
This experienceLayout. jspAs follows::
<% @
Page contenttype = "text/html; charset = UTF-8" %>
<% @
Taglib uri = "../WEB-INF/struts-tiles.tld" prefix = "tiles"
%>
<HTML>
<Head>
<Title> <tiles: insertattribute
Name = "title"/> </title>
</Head>
<Body>
<Table width = "768px"
Height = "800px" border = "2" align = "center">
<Tr>
<TD colspan = "2"
Align = "center" valign = "TOP" width = "768px"
Height = "100px" bgcolor = "#80ff80">
<Tiles: insertattribute
Name = "Header"/>
</TD>
</Tr>
<Tr>
<TD align = "center"
Width = "150px" Height = "800px"
Bgcolor = "#00ff00">
<Tiles: insertattribute
Name = "menu"/>
</TD>
<TD align = "left"
Width = "618px" Height = "800px"
Bgcolor = "# ff80c0">
<Tiles: insertattribute
Name = "body"/>
</TD>
</Tr>
<Tr>
<TD colspan = "2"
Bgcolor = "#00ff40" Height = "100px">
<Tiles: insertattribute
Name = "footer"/>
</TD>
</Tr>
</Table>
</Body>
</Html>
Layout. jspBased on the customTiles. xmlLayout
TilesConfiguration item |
LayoutItem |
Title |
<Tiles: insertattribute Name = "title"/> |
Header |
<Tiles: insertattribute Name = "Header"/> |
Menu |
<Tiles: insertattribute Name = "menu"/> |
Body |
<Tiles: insertattribute Name = "body"/> |
Footer |
<Tiles: insertattribute Name = "footer"/> |
The page layout has been initially completed.
4, Define Content Page
Define the content page as needed, suchTiles. xmlIn configurationIndexInherited from the MyApp. Homepage template, but the content is changed to a custom content page.
<Definition
Name = "Index" extends = "MyApp. Homepage">
<Put-attribute
Name = "body" value ="/Content/indexcontent. jsp"/>
</Definition>
Indexcontent here. JspFor custom page content
<% @
Page Language = "Java" Import = "Java. util .*"
Pageencoding = "gb2312" %>
<% @
Taglib prefix = "S" uri = "/Struts-tags" %>
<
Href = "<s: URL action = 'LIST'/>"> List </a>
Here is just a simpleLinkPointList action
5, Compile the actual access page
The next compilation of the actual access page is relatively simple. Here we useIndex. jspExample
You only need to useTilesCan be defined in
<% @
Page Language = "Java" Import = "Java. util .*"
Pageencoding = "gb2312" %>
<% @
Taglib uri = "WEB-INF/struts-tiles.tld" prefix = "tiles" %>
<% @
Taglib prefix = "S" uri = "/Struts-tags" %>
<Tiles: insertdefinition name = "Index"/>
The basic configuration has been completed so far.
6To combineTilesInWeb. xmlAdd the following configuration
<Context-param>
<Param-Name> org. Apache. Tiles. impl. basictilescontainer. definitions_config </param-Name>
<Param-value>/WEB-INF/tiles. xml </param-value>
</Context-param>
<Listener>
<Listener-class> org. Apache. struts2.tiles. strutstileslistener </listener-class>
</Listener>
7, Run to see the effect of the template page