skip to main | skip to sidebar

Wednesday, October 27, 2010

Using Multiple Struts Config Files

If you are working on a big web application which uses Struts and has huge number of action classes in it, action mappings for these classes will result a huge “struts-config.xml'” file. You might always find it difficult to change the struts config file that big. And it might be really helpful if you split the action mappings and put them in multiple config files, splitting can be based on any criteria – based on functionality or authorization levels, etc. Lets see how we can do this and use multiple ‘struts-config.xml’ files.
Lets say that you’ve three struts config files namely “struts-config-1.xml”, “struts-config-2.xml”, and “struts-config-3.xml”. All you need to do is specify these configuration files as initialization parameter ‘config’ for “ActionServlet” in your ‘web.xml’ file. Make sure that all your config files should be separated with ‘comma’, see the example given below.
<servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>
        org.apache.struts.action.ActionServlet
    </servlet-class>
    <init-param>
        <param-name>config</param-name>
        <param-value>
            /WEB-INF/struts-config-1.xml,/WEB-INF/struts-config-2.xml,/WEB-INF/struts-config-3.xml
        </param-value>
    </init-param>
    …
</servlet>
That’s it, quite easy isn’t it!
Read more »»