To use tiles in struts, ensure that the page correctly introduces the struts-tiles.tld, that is, <% @ taglib uri = "/tags/Struts-tiles" prefix = "tiles" %>. In addition, the struts-config.xml configuration is as follows:
<Plug-in classname = "org. Apache. Struts. Tiles. tilesplugin">
<! -- Path to XML definition file -->
<Set-Property = "definitions-config" value = "/WEB-INF/tiles-defs.xml"/>
<! -- Set Module-awareness to true -->
<Set-Property = "moduleaware" value = "true"/>
</Plug-in>
<Controller processorclass = "org. Apache. Struts. Tiles. tilesrequestprocessor"/>
In
// Define a motherboard
<Definition name = ". mainlayout" Path = "/common/layouts/classiclayout. jsp">
<Put name = "title" value = "Sample page title"/>
<Put name = "Header" value = "/common/header. jsp"/>
<! -- Put name = "menu" value = ". mainmenu"/-->
<Put name = "footer" value = "/common/footer. jsp"/>
<Put name = "body" value = ""/>
</Definition>
In the classiclayout. jsp file:
<% @ Page contenttype = "text/html; charset = UTF-8" Language = "Java" %>
<! -- % @ Taglib uri = "/WEB-INF/struts-tiles.tld" prefix = "tiles" % -->
<% @ Taglib uri = "/tags/Struts-tiles" prefix = "tiles" %>
<HTML>
<Head> <title> simple JSP page </title> <Body bgcolor = "# ffffff" text = "#000000" link = "#023264" alink = "#023264" vlink = "#023264">
<Table border = "0" width = "100%" cellspacing = "5">
<Tr>
<TD colspan = "2"> <tiles: insert attribute = "Header"/> </TD>
</Tr>
<Tr>
& Lt; TD width = "140" valign = "TOP" & gt;
<! -- Tiles: insert attribute = 'menu '/-->
</TD>
<TD valign = "TOP" align = "Left">
<Tiles: insert attribute = 'body'/>
</TD>
</Tr>
<Tr>
<TD colspan = "2">
<Tiles: insert attribute = "footer"/>
</TD>
</Tr>
</Table>
</Body>
</Html>
// Define the child board, which inherits the parent board through extends
<Definition name = "ordertiles" extends = ". mainlayout">
<Put name = "body" value = "/pages/order. jsp"/>
</Definition>
// Define an action that directs to the tiles template.
<Action Path = "/ordertiles" type = "org. Apache. Struts. Actions. forwardaction" parameter = "ordertiles"> </Action>
// Define an action, whose forward path is an action containing the tiles Template
<Action Path = "/editorder" type = "heroking. Action. editorder"
Name = "orderform" Scope = "request"
Validate = "false">
<Forward name = "success" Path = "/ordertiles. Do"/>
</Action>
<Action Path = "/submitorder" type = "heroking. Action. submitorder"
Name = "orderform" Scope = "request"
Validate = "false">
<Forward name = "success" Path = "/ordertiles. Do"/>
</Action>
You can.