Struts2 Multiple Configuration Bean XML Files

Struts allows to create multiple struts configuration xml files and include same in struts.xml file using <include file=””> tag.

  1. Below is the folder structure we will be following as part of current implementation.

2. Lets create user-struts.xml file inside src folder having unique name and namespace as shown in below screenshot.

3. Lets create one more address-struts.xml inside src folder having unique name and namespace as shown in below screenshot.

4. include both the struts config xml files inside main struts.xml file as show below.

Note: struts.xml file can not have duplicate namespace. It will load and pick the first included at first position in struts.xml incase of duplicate namespace.

5. Create UserAction.java and AdressAction.java class file with below content.

6. As discussed earlier, namespace update will require to create folder with the same name of namespace as user-pack and address-pack.

OUTPUT:

http://localhost:8081/struts-demo/user-pack/user.action

http://localhost:8081/struts-demo/address-pack/address.action

Imran Khan, Adobe Community Advisor, AEM certified developer and Java Geek, is an experienced AEM developer with over 11 years of expertise in designing and implementing robust web applications. He leverages Adobe Experience Manager, Analytics, and Target to create dynamic digital experiences. Imran possesses extensive expertise in J2EE, Sightly, Struts 2.0, Spring, Hibernate, JPA, React, HTML, jQuery, and JavaScript.

0