更改Struts的配置文件struts.xml 默认目录路径到WEB-INF
2012-07-20 14:28
375 查看
我的文件目录
-src
-WEB-INF
--classes
--lib
--struts-config-sale.xml
--struts-config-hr.xml
--struts.xml
--web.xml
在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>
注意../struts.xml前面有两个点,表示上级目录,struts2默认查找的是/WEB-INF/classes下的配置文件,所以要返回上级目录去查找struts.xml
如果在struts.xm中的如果要包含其他struts的配置文件,也要更改目录
<struts>
...
<include file="../struts-config-sale.xml" />
<include file="../struts-config-hr.xml" />
</struts>
源代码:
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");
}
}
}
所以上面的配置只是改变了读取配置文件的变量值,struts2始终还是从/WEB-INF/classes目录下开始搜索配置文件。这样配置就OK了,不需要修改其他的。
-src
-WEB-INF
--classes
--lib
--struts-config-sale.xml
--struts-config-hr.xml
--struts.xml
--web.xml
在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>
注意../struts.xml前面有两个点,表示上级目录,struts2默认查找的是/WEB-INF/classes下的配置文件,所以要返回上级目录去查找struts.xml
如果在struts.xm中的如果要包含其他struts的配置文件,也要更改目录
<struts>
...
<include file="../struts-config-sale.xml" />
<include file="../struts-config-hr.xml" />
</struts>
源代码:
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");
}
}
}
所以上面的配置只是改变了读取配置文件的变量值,struts2始终还是从/WEB-INF/classes目录下开始搜索配置文件。这样配置就OK了,不需要修改其他的。
相关文章推荐
- java基础(安装/调试/记事本编写/web-inf目录/配置JRE,tomcat/查看虚拟路径/修改tomcat默认端口号)
- java获取WEB-INF目录绝对路径
- WEB-INF 有关的目录路径问题总结
- WEB-INF有关的目录路径问题总结
- Struts如何访问WEB-INF目录下的jsp文件。
- jsp放在WEB-INF下的访问(struts访问路径)
- WEB-INF 有关的目录路径问题总结
- web.xml中改变struts.xml默认路径
- servlet struts 取上下文路径 和 WEB-INF路径
- Eclipse 如何将Web项目的默认编译输出目录改为WEB-INF/classes?
- Struts如何访问WEB-INF目录下的jsp文件。
- WEB-INF有关的目录路径总结
- 转:如何从普通Java类中获取WEB-INF目录绝对路径
- 如何获得java工程或者java web工程中的src目录中的文件和webinf目录路径
- WAMPServer默认配置更改-web根目录
- 关于WEB-INF目录下页面的资源访问路径问题
- struts1了解和WEB-INF受保护目录下jsp的访问
- 不同web服务器获取WEB-INF目录路径
- Eclipse发布项目默认编译输出目录改为WEB-INF/classes
- Web服务基础七之Apache日志文件管理、默认网站目录更改、防止php木马跨站设置、禁止空主机头 推荐