Struts Tiles Integration

Hi All,

This post will be focused on integrating Tiles framework with Struts 1.x.

Following are the code snippets.

1) Add a plug in for Tiles in struts-config.xml.
Here is the struts-config.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"


<!-- Data Sources -->

<!-- Form Beans -->

<!-- Global Exceptions -->

<!-- Global Forwards -->

<!-- Action Mappings -->
<action path="/HomePage" forward="" />

<!-- Message Resources -->

<!-- Plug Ins -->

<plug-in className="org.apache.struts.tiles.TilesPlugin">
<set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />
<set-property property="moduleAware" value="true" />


2) Write a Layout.jsp page. This page will serve as a template. We create attributes in this jsp page that will be substituted by actual jsp pages defined in tiles-defs.xml.

Here is Layout.jsp page

<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>

<table border="1" cellpadding="2" cellspacing="2" align="center">

<td height="20%" colspan="2">
<tiles:insert attribute="header" />

<td height="60%" colspan="2">
<tiles:insert attribute="body" />

<td height="20%" colspan="2">
<tiles:insert attribute="footer" />


3) Write a tiles-defs.xml file. We write definitions of all the web pages that should obey the template created in step 2. We declare the name (attribute name in jsp page) value (actual jsp page to be substituted) pair. This xml file (as all xml files) should be in /WEB-INF folder of the application.

Here is the tiles-defs.xml file:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 1.3//EN"

<definition name="" page="/Layout.jsp">
<put name="header" value="/Header.jsp" />
<put name="body" value="/Body.jsp" />
<put name="footer" value="/Footer.jsp" />


4) web.xml file.
Here is the code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "">
<web-app id="WebApp">






Now we have made the initial set up for using tiles.
We are just left with writing the jsp files that will be displayed using Tiles.

5) Write index.jsp page.
Here is the code:

<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html:link action="HomePage">Using Tiles in Struts</html:link>

6) Write Header.jsp page.
Here is the code:

You are in header page!!!!

7) Write Body.jsp page.
Here is the code:

You are in body page!!!!

8) Write Footer.jsp page.
Here is the code:

You are in footer page!!!

Thats it!!!

Hope your code works.

Thanks for taking the time to reading my post!

If you like my code, feel free to leave comments 🙂

Best Regards


About Badal Chowdhary

I am a Software Engineer by profession. I have done SCJP and SCWCD certifications. Like working on cutting edge technologies and frameworks. Driven by challenges and fascinated by technology. I love playing and watching sports: Cricket, Ping Pong, Tennis, Badminton, Racket Ball and Gym.
This entry was posted in Struts and tagged , . Bookmark the permalink.

One Response to Struts Tiles Integration

  1. chandrasekhar says:

    Hei Badal,
    Your code was very much helpful to me and has solved some of my doubts too.I could find the amount of hard work u have put on this. Continue your hard work and help many more people like me the same way.
    Best of Luck

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s