Child pages
  • Tiles Plugin

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin


The Tiles plugin


allows actions to return Tiles pages



  • Supports Tiles in Freemarker, JSP, and Velocity
  • Provides annotations to keep tiles.xml short and put definitons into actions


The following steps must be taken in order to enable tiles support within your Struts2 application:

  1. Include the struts-tiles-plugin as a dependency in your web application. If you are using maven2, the dependency configuration will be similar to:

    Code Block
  2. Register the tiles listener. This listener will typically either be the standard tiles listener (org.apache.tiles.listener.TilesListener) or the Struts2 replacement (org.apache.struts2.tiles.TilesListener). The latter provides tighter integration with Struts features such as freemarker integration.

    Code Block
  3. All package definitions which require tiles support must either extend the tiles-default package or must register the Tiles Result type definition.

    Code Block
      <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/>
  4. Configure your actions to utilize a tiles definition:

    Code Block
    <action name="sample" class="org.apache.struts2.tiles.example.SampleAction" >
      <result name="success" type="tiles">tilesWorks</result>
  5. Instead of xml configuration you can use annotations

    Code Block
    @Result(name = "success", type="tiles")
    @TilesDefinition(extend = "fooLayout", putAttributes = {
        @TilesPutAttribute(name = "header", value = "/WEB-INF/tiles/header.jsp"),
        @TilesPutAttribute(name = "body", value = "/WEB-INF/tiles/body.ftl")
    public class FooAction extends ActionSupport {
  6. You have to define Tiles Definitons in a tiles.xml file. That can be placed in resources or in WEB-INF.

    Code Block
    <!DOCTYPE tiles-definitions PUBLIC
            "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
        <definition name="fooLayout" template="/WEB-INF/tiles/layout.jsp">
            <put-attribute name="title" value="Tiles Sample"/>
            <put-attribute name="header" value=".header"/>
            <put-attribute name="body" value=".bodyp"/>
        <definition name="tilesWorks" extends="fooLayout">
            <put-attribute name="header" value="/WEB-INF/tiles/header.jsp"/>
            <put-attribute name="body" value="/WEB-INF/tiles/body.jsp"/>

As from Struts 2.3.28, the plugin automatically loads all Tiles definitions matching the following pattern tiles*.xml - you don't have to specify them via org.apache.tiles.definition.DefinitionsFactory.DEFINITIONS_CONFIG in web.xml, but you can use this option if your application is going to work in restricted servlet environment e.g. Google AppEngine. In such case, defintions will be read from provided init-param.


This example shows a Tiles layout page using Struts tags:

Wiki Markup
Please check tiles example in struts-examples project.


This plugin does not have any global settingsinherits settings from Tiles configuration.


This plugin can be installed by copying the plugin jar into your application's /WEB-INF/lib directory. No other files need to be copied or created.