By having multiple struts configuration files it will be easy to maintain and debug. Here we work with a single module, so you can split the configuration file according to your convenience. During the startup the ActionServlet will read all the configuration files and create a database of configuration objects, which it will later refer while processing the request.
Let's see how it works. The struts-config.xml files contains the following piece of code.
In the sample action classes we simply return "success". So according to the configuration when the request URI is sample1 the user will be forwarded to sample1.jsp and when the request URI is sample2 the user will be forwarded to the sample2.jsp page.
Now let's try with the request URI sample1. In the index.jsp page we forward the request to the URI sample1.
When you execute the application the sample1.jsp is displayed to the user.
In the same way you can try with the request URI sample2.
If you are working with multiple modules in your project, then you can have one configuration file for each modules. Let's say the project has two modules admin and reports. You access the admin screens using the URI admin/admin-module1 and reports using the URI report/report-1. Here the admin and report are two different modules. The following code shows how to create a seperate configuration file for each module.
Here the param-name should be config/moduleName and the param-value should be the corresponding configuration file. If you have more than one file for that particular module you can add them seperated by commas.
The struts configuration for admin module is done in the struts-config-admin.xml file.
In the AdminAction class we simply forward "success". The important thing to note is that in the configuration file the value of the path attribute is /admin1 and to invoke this we need to specify admin/admin1.do as the URI in the jsp page because it is there inside the admin module.
In the jsp page.
On executing the example the user will be forwarded to the admin.jsp page which should be placed inside the admin directory.
The directory structure of the example look like this.
You can download the source code of this example by clicking on the Download link below.