Multi namespace

Multi namespace is very interesting topic where small change can load code from different directory depending on the name space defined in struts.xml

1. In struts we can define multiple namespace inside struts.xml file as highlighted in below file. e.g. namespace=”/”

 It will generate an URL depending upon namespace as given below.

http://localhost:8081/struts-demo/<namespace>/<struts_action>

2. We have created namespace with name as /, /one, /two

This will require a change in the project code structure to add one and two folder inside WebContent folder as highlighted below red in color.

3. Update content of UserAction.java class file to below one:

4. Create a folder name as one, parallel to WEB-INF folder, create welcome.jsp file and paste below content in that file.

5. Create one more folder name as two, parallel to WEB-INF folder, create welcome.jsp file and paste below content in that file.

6. In multiple namespace if we hit the URL, it will read data from different directory depending upon namespace as show below.

OUTPUT:

http://localhost:8081/struts-demo/user.action
Hitting the above URL will read data from root folder welcome.jsp file.

http://localhost:8081/struts-demo/one/user.action
Hitting the above URL will read data from one folder welcome.jsp file.

http://localhost:8081/struts-demo/two/user.action
Hitting the above URL will read data from two folder welcome.jsp file.

Imran Khan

Specialist Master (Architect) with a passion for cutting-edge technologies like AEM (Adobe Experience Manager) and a proven track record of delivering high-quality software solutions.

  • Languages: Java, Python
  • Frameworks: J2EE, Spring, Struts 2.0, Hibernate
  • Web Technologies: React, HTML, CSS
  • Analytics: Adobe Analytics
  • Tools & Technologies: IntelliJ, JIRA

🌐 LinkedIn

📝 Blogs

📧 Imran Khan