Struts Tiles framework example

Struts Tiles framework is a layout framework, which allow users to maintain a standard look of header, footer and menu across all of your web pages efficiently.

Download this example –

Tiles template example

Here’s an example to create a tiles template to maintain the header and footer details across all of the web pages in Struts.

Firstly, see this Struts tiles framework relationship.

1. Get Struts Tiles Library

Get the struts tiles library from the Struts distribution folder, or via Maven central repository


and include it in your project dependency library.

2. Create a Template

Create a template red and template green for header and footer details. These two templates are just pure HTML code with different background color..

Template – Red color

<div style="padding:16px;background-color:red">
<h1>[Logo Here] This is Template Red Header</h1>


<div style="padding:16px;background-color:red">
<h1>This is Template Red Footer</h1>

Template – Green color

<div style="padding:16px;background-color:green">
<h1>[Logo Here] This is Template Green Header</h1>


<div style="padding:16px;background-color:green">
<h1>This is Template Green Footer</h1>

3. Tiles layout

Create a standard web page layout for all of your web pages.


<%@ taglib uri="" prefix="tiles" %>
<tiles:insert attribute="header"/>
<tiles:insert attribute="body"/> 
<tiles:insert attribute="footer"/> 

4. Body Template

In the body template, you should always create two pages “user-form.jsp and user-form-body.jsp” for body details to break the coupled with tiles framework. The “user-form.jsp” is used to get the tiles definition, and “put” the real body content (user-form-body.jsp) as body template.


<%@ taglib uri="" prefix="tiles" %>
<tiles:insert definition="company-template" >
	<tiles:put name="body" value="/pages/user/body/user-form-body.jsp" />


<div style="padding:16px;background-color:blue;height:200px;">
<h1>This is body content </h1>

5. Tiles Definition

All the templates are done, create a “tiles-defs.xml” file and declared a “company-template” definition for red template.


<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 1.3//EN"
   <definition name="company-template" path="/pages/tiles/common-layout.jsp">
	<put name="header" value="/pages/tiles/template-red/header.jsp" />
	<put name="footer" value="/pages/tiles/template-red/footer.jsp" />

6. Include the TilesPlugin

To use Struts tiles framework, you have to declare the “TilesPlugin” plug-in class in the Struts configuration file.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC 
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" 
	<plug-in className="org.apache.struts.tiles.TilesPlugin" >
		<set-property property="definitions-config"

7. Demo

In above case, the template red is used.



To change it to template green, you just need to update the “tiles-defs.xml” file.


<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 1.3//EN"
   <definition name="company-template" path="/pages/tiles/common-layout.jsp">
	<put name="header" value="/pages/tiles/template-green/header.jsp" />
	<put name="footer" value="/pages/tiles/template-green/footer.jsp" />

Access it again



The header and footer color is changed (template green), with just a minor changes in the tiles configuration file.


Struts Tiles Documentation –

Tags :

About the Author

Founder of and, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.


  • Lisa

    What is the standard process of using forms in tiles?
    Suppose I have a tiles definition with a left and right panel, and I need to use a common form across the two. Is this possible?
    If now, how do I use the 2 instances of the same form together/synchronize the 2 forms?

  • Nitin

    what to do at the time of logout. showing logout.jsp (should not follow the pattern)

  • soniya gupta

    Very much helpful tutorial. Requesting you to please upload tutorial on java web services.

  • isharag

    can you please tell me how can i change the “http://localhost:8080/Elg/” to “http://localhost:8080/Elg/User”.

  • Anji

    I am getting “Attribute property has a runtime value of config-. property must reference a valid Java identifier.” this error

    when I am working in RAD. I have no clue. Please help me out. Thanks in advance.

  • Santosh

    Can you please provide struts+tiles+velocity example


  • mahesh

    help how to integrate struts and hibernate

  • Yashod

    I started learning Tiles Framework from multiple sites and I found, it is very confusion. Once, I started reading this article, I understood, the framework very much easily.

    Thanks for posting nice article !!!

  • xtian

    You’re using the old tag library.
    See here:

  • Narsimha

    Good Article,thanx.

  • Pingback: Struts Tutorials | Tutorials()