With Struts2 we have to have struts.xml
in the class path, so it no longer works to have it under WEB-INF. So the way I got my project to deploy was to stick it under WEB-INF/classes
and have it include ../struts2.xml
2 Problems:
struts.xml
How are you Struts2 Eclipse developers doing this?
xml file of the fault module is represented as fault-struts-config. xml and is present in <Web NMS Home>/webclient/fault/conf directory. The configuration file basically contains three main elements: <form-beans>
In the web. xml file, Struts defines its FilterDispatcher, the Servlet Filter class that initializes the Struts framework and handles all requests. This filter can contain initialization parameters that affect what, if any, additional configuration files are loaded and how the framework should behave.
The struts. xml file contains the configuration information that you will be modifying as actions are developed. This file can be used to override default settings for an application, for example struts. devMode = false and other settings which are defined in property file.
The struts application contains two main configuration files struts. xml file and struts.
You can either just put the struts.xml at the root of your source directory or set up an additional resources source directory and put it there. Eclipse quite happily copies it to WEB-INF/classes for you when it does a compilation.
I am late to the party, we can configure the struts.xml in any directory in the classpath of the web application, but provide the location using the "config" init parameter of the filter configuration in web.xml as below, if my struts.xml file is in "/com/resources/" directory.
<filter>
<filter-name>action</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>config</param-name>
<param-value>struts-default.xml,struts-plugin.xml,/com/resources/struts.xml</param-value>
</init-param>
</filter>
If we don't provide a config init parameter struts2 by default takes 3 values "struts-default.xml,struts-plugin.xml,struts.xml", you can see the struts2 Dispatcher class code below which will configure these 3 files to the configuration manager.
String configPaths = (String)this.initParams.get("config");
if (configPaths == null) {
configPaths = "struts-default.xml,struts-plugin.xml,struts.xml";
}
String[] files = configPaths.split("\\s*[,]\\s*");
for (String file : files)
if (file.endsWith(".xml")) {
if ("xwork.xml".equals(file))
this.configurationManager.addContainerProvider(createXmlConfigurationProvider(file, false));
else
this.configurationManager.addContainerProvider(createStrutsXmlConfigurationProvider(file, false, this.servletContext));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With