
[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.
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.