Cheap VPS & Xen Server

Residential Proxy Network - Hourly & Monthly Packages

Multi Configuration


For a large application, it is better to use multiple configuration file that one so that it may be easy to manage the application.

We can create many configuration files but we need to define it in the struts.xml file. The includesub-element of struts is used to define the supported configuration file.

Example to create multiple configuration files

Let’s see the simple example to define multiple configuration files.

1) Define entry of multiple configuration files in struts.xml

In this struts.xml file, we have defined 2 configuration files struts-first.xml file and struts-second.xml file.

The struts-first.xml file is located inside the first directory and struts-second.xml file is located inside the second directory.

struts.xml

  1. <?xml version=“1.0” encoding=“UTF-8” ?>
  2. <!DOCTYPE struts PUBLIC “-//Apache Software Foundation//DTD Struts
  3.  Configuration 2.1//EN” “http://struts.apache.org/dtds/struts-2.1.dtd”>
  4. <struts>
  5. <package name=“default1” namespace=“/” extends=“struts-default”>
  6. </package>
  7. <include file=“first/struts-first.xml”></include>
  8. <include file=“second/struts-second.xml”></include>
  9. </struts>

2) Create configuration files

Let’s create two configuration files that defines action with results.

struts-first.xml

  1. <?xml version=“1.0” encoding=“UTF-8” ?>
  2. <!DOCTYPE struts PUBLIC “-//Apache Software Foundation//DTD Struts
  3.  Configuration 2.1//EN” “http://struts.apache.org/dtds/struts-2.1.dtd”>
  4. <struts>
  5. <package name=“first” namespace=“/first” extends=“struts-default”>
  6. <action name=“hello”  class=“com.Kreationnext.Welcome”>
  7. <result>welcome.jsp</result>
  8. </action>
  9. </package>
  10. </struts>

struts-second.xml

  1. <?xml version=“1.0” encoding=“UTF-8” ?>
  2. <!DOCTYPE struts PUBLIC “-//Apache Software Foundation//DTD Struts 
  3. Configuration 2.1//EN” “http://struts.apache.org/dtds/struts-2.1.dtd”>
  4. <struts>
  5. <package name=“second” namespace=“/second” extends=“struts-default”>
  6. <action name=“hello”  class=“com.Kreationnext.Welcome”>
  7. <result>welcome.jsp</result>
  8. </action>
  9. </package>
  10. </struts>

Other Required Resources

To run this application, we need following resources:

  1. index.jsp
  2. Welcome.java
  3. 2 View Components

index.jsp

This jsp page creates two links.

index.jsp

  1. <a href=“first/hello”>first namespace</a>|
  2. <a href=“second/hello”>second namespace</a>

Action class

It is the simple Action class containing only execute method.

Welcome.java

  1. package com.Kreationnext;
  2. public class Welcome {
  3. public String execute(){
  4.     return “success”;
  5. }
  6. }

2 view components

The name of 2 view components are same i.e. welcome.jsp but both are located differently.

welcome.jsp

It is located inside the first directory under root.

  1. <h1>Welcome to first namespace</h1>
  2. </pre></div>
  3. <strong>welcome.jsp</strong>
  4. <p>It is located inside the second directory under root.</p>
  5. <div class=“codeblock”><pre name=“code” class=“java” >
  6. <h1>Welcome to second namespace</h1>

Comments

comments