Change struts configuration file struts.xml default directory path to Web-inf

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.