My file directory
-src
-web-inf
--classes
--lib
--struts-config-sale.xml
--struts-config-hr.xml
--struts.xml
--web.xml
Add in the Web.xml
<filter>
<filter-name>struts</filter-name>
<filter-class>
Org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
<init-param>
<param-name>config</param-name>
<param-value>struts-default.xml,struts-plugin.xml,.. /struts.xml</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
Attention.. /struts.xml Front has two points, indicating the superior directory, struts2 The default lookup is/web-inf/classes under the configuration file, so to return to the superior directory to find Struts.xml
If you want to include other struts profiles in Struts.xm, also change the directory
<struts>
...
<include file= ". /struts-config-sale.xml "/>
<include file= ". /struts-config-hr.xml "/>
</struts>
Source:
private static final String default_configuration_paths = "Struts-default.xml,struts-plugin.xml,struts.xml";
private void Init_traditionalxmlconfigurations () {
String configpaths = initparams.get ("config");
if (configpaths = = null) {
Configpaths = default_configuration_paths;
}
string[] files = Configpaths.split ("\\s*[,]\\s*");
for (String file:files) {
if (File.endswith (". xml")) {
if ("Xwork.xml". Equals (file)) {
Configurationmanager.addconfigurationprovider (New Xmlconfigurationprovider (file, false));
} else {
Configurationmanager.addconfigurationprovider (New Strutsxmlconfigurationprovider (file, False, ServletContext));
}
} else {
throw new IllegalArgumentException ("Invalid configuration file name");
}
}
}
So the above configuration simply changes the value of the variable reading the configuration file, and struts2 always start searching the profile from the/web-inf/classes directory. This configuration is OK, no need to modify the other.