Multiple namespaces example in Struts2

I will show you here how to create multiple namespaces in struts2 web application. The benefit of namespace is the same file and action can be mapped to the multiple modules.

First create the web application using any JEE based IDE like Eclipse.
Make sure that the following jars exist in the WB-INF/lib directory. Please download the following jar files from the respective site.

file upload example in struts
We can define multiple namespaces in struts.xml file by the namespace attribute of package element. The default namespace is /(root).

Look at the below picture how namespace in the URL is mapped.

namespace example in struts

1. Creating Action class


2. Namespace Configurations

Namespace is configured in the struts.xml file. The below file shows there are three namespaces – “/” or root, common and user.


namespace example in struts
3. JSP Pages



Below JSP pages with same file name but locate at different modules.







4. Mapping







Once you run the application you will see the following page. Now you can navigae to any of the namespaces.
namespace example in struts

Thanks for your patience. Please do not forget to leave a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.