Elsie esq.
Photo credit: Elsie esq.
del.icio.us Digg DZone Reddit StumbleUpon
1 | 2 | 3 | Next »
Software Development

Adding Modules to a Struts/Tiles Application

Use Struts modules to tidy up your Struts/Tiles application.

[I wrote this article some years back for Struts 1.2.7. It may work for Struts 1.3.x as well though I haven't actually tried that. — Willie]

In this article I'm going to show you how to add modules to an existing Struts/Tiles project. First we'll start by separating out the Struts part, without separating out the Tiles part. Once we get that working, we'll move on to separating the Tiles definitions as well.

Modify web.xml

In web.xml, the ActionServlet definition needs to contain one init param for each module in your app. For the sake of example, let's consider my web site. [I wrote this article when I had a personal web site that used Struts and Tiles — Willie] I have a default module, an articles module, and a software module. (My web site is probably too small to warrant subdivision into modules, but being small makes for a good example.) Here's my ActionServlet definition:

<servlet>
    <servlet-name>ActionServlet</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
        <param-name>config</param-name>
        <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
        <param-name>config/articles</param-name>
        <param-value>/WEB-INF/struts-config-articles.xml</param-value>
    </init-param>
    <init-param>
        <param-name>config/software</param-name>
        <param-value>/WEB-INF/struts-config-software.xml</param-value>
    </init-param>
</servlet>

The default module handles requests that aren't handled by the other two modules. Notice that the param names have slashes. The filenames themselves can be whatever you like; I've followed standard convention in using the format struts-config-xxx.xml.

(Don't forget the servlet mapping.)

You'll also need to make sure that you define the Tiles taglib in web.xml. Moreover, in most cases you'll want to have the Struts taglibs as well, since they are module-aware. Here are the definitions that I have:

<taglib>
    <taglib-uri>/tags/struts-bean</taglib-uri>
    <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
    <taglib-uri>/tags/struts-html</taglib-uri>
    <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
    <taglib-uri>/tags/struts-logic</taglib-uri>
    <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
<taglib>
    <taglib-uri>/tags/struts-tiles</taglib-uri>
    <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
</taglib>

That does it for web.xml. Now let's do the module config files.

Social bookmarks: del.icio.us Digg DZone Reddit StumbleUpon
1 | 2 | 3 | Next »

Comments (4)

Quinceanera Dresses Best canon Coffee Mugs! Funny, Cute, & Humorous Unique designs. Also find Travel Mugs, Coffee Cups also, or Create Photo Personalized Mugs & Drinkware canon mugs canon lens mugs Nikon Mugs Canon Coffee Lens Mug Nikon Coffee Lens Mug anon coffee mug,canon lens mug,canon mug,canon coffee cup,canon thermos travel mug Canon 70-200mm Lens Coffee Mug

By dress on Aug 30, 2010 at 2:56 AM PDT

Quinceanera Dresses Best canon Coffee Mugs! Funny, Cute, & Humorous Unique designs. Also find Travel Mugs, Coffee Cups also, or Create Photo Personalized Mugs & Drinkware canon mugs canon lens mugs Nikon Mugs Canon Coffee Lens Mug Nikon Coffee Lens Mug anon coffee mug,canon lens mug,canon mug,canon coffee cup,canon thermos travel mug Canon 70-200mm Lens Coffee Mug

By dress on Aug 30, 2010 at 2:56 AM PDT

he myth of pandora is ancient, appears in several distinct Greek versions, pandora armbandand has been interpreted in many ways. In all literary versions, Neu Eingetroffen however, Pandora Armbänder the myth is a rosetta stone kind of theodicy, addressing the question pop information, web easy get, sports fashion, news-fashionof why there is evil in the world. In the seventh hot-winter century BC, Hesiod, both in his Theogony (briefly, without naming Pandora outright rosetta stone language, rosetta stone spanish, abercrombie and fitch, Abercrombie Fitch

By pandora schmuck on Aug 30, 2010 at 10:58 PM PDT

Post a comment

Your name:
Your e-mail address (won't be displayed):
Your web site (optional):
example: www.xyz.com
Your comment:
Preview:
By You
Please help us reduce comment spam:
Spring Annotations RefCard
Check out the new DZone Spring Annotations Refcard by Craig Walls!

What's New?

2009-08-30 - Check out my two-part series on DZone: Spring Integration: A Hands-On Tutorial.
2009-03-25 - My new article Getting Started with Spring Batch 2.0 is available on DZone.
Home | Consulting | Tech Articles | Mailing List | Contact | Spring Blog
Copyright © 2008 Wheeler Software, LLC.