YOU ARE HERE: Home > Tutorial > Tutorial > Article

Struts Tile Tutorial
By John Henry Xu This article was rated:
 
Printer Version Printer Friendly | Add As Favorite | Link to Article

About the Author

Dr. John Xu (also known as Jack Xu) is a seasoned system architect. He was chief architect for large distributed portals. He also developed search engine and Java forums. He can be reached by email xixu@yahoo.com.

Struts framework provides tile library that can divide UI -- web page -- into different areas (tiles).

Tile library makes web application look and feel more consistent and easy to change.


This tutorial, I will show simple steps of creating tiles for web pages.

1. Create a layout.
2. Use Definition file
3. Create web page with tile tags.


You should have struts installed on Tomcat server. If you don??t know how to install struts and Tomcat,

you may refer to their documents, or read the article

Step 1. Create a layout

Assume we create a web page that has header, body and footer tiles (sections). I create a web page

layout called MyLayout.jsp page.

List 1. MyLayout.jsp


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

<html:html>
<head>
<title><bean:message key="application.title"/></title>
</head>
<body>

<tiles:insert attribute="header"/>
<tiles:insert attribute="body"/>
<tiles:insert attribute="footer"/>

</body>
</html:html>

application.title is defined in your struts application resource file.

Step 2. Use definition file

If some tiles in MyLayout.jsp appears in other pages in web application, the best practice is to put these common tiles to a definition file.

Assume header and footer tiles are common tiles, you may write a definition file including these two tiles

List 2. CommonTile.jsp


<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%>
<tiles:definition id="usanalyst.common" page="MyLayout.jsp" scope="request">
<tiles:put name="header" value="myHeader.jsp" />
<tiles:put name="footer" value="myFooter.jsp" />
</tiles:definition>

where myHeader.jsp is your header jsp file, and myFooter.jsp is your footer jsp file.


Step 3. Create web page with tile tags


Now we create the web page myPage.jsp


List 3. myPage.jsp


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

<tiles:insert beanName="usanalyst.common" beanScope="request">
<tiles:put name="body" value="body.jsp" />
</tiles:insert>

where body.jsp is the jsp page you implement for body section.


Summary


I have shown how easy the struts tile can be implemented with 3 simple steps. Now try to use tile in your struts applications.


Was this article helpful to you?yesno
1 of 1 people found this article helpful.



Related Publications
 
A quick way to create grids in Photoshop
Struts Tile Tutorial
Using Axis SOAPMonitor
How to fix RedHat 9 ftp server problem
Use Apache with Web Application Server
Install and Use Apache Web Server
Verify the signature of downloaded files
Quick tutorial about finding MAC address of your PC
HIPAA Introduction (Part 2)
HIPAA Introduction (Part 1)

(Registered users can post questions/comments)

 
 TLINKS SEARCH
Advanced Search
Help
 Recommended Links
Red Cross
Responding to hurricane katrina relieve. Donate today. It's a Great Feeling to Help.
http://www.redcross.org
Getusjobs.com
Getusjobs.com is the job site focused on American jobs. See the results that put us on top.
http://www.getusjobs.com
Database Tool
TLinkSoft® tools empowers developers, integrators and DBAs to be more productive.
http://www.cppunit.org/download.jsp
USAnalyst.com
USAnalyst.com provide a community for database analysts, business analysts, developer analysts and managers.
http://www.cppunit.org/article

Powered by Tlinks Systems