在哪里放置struts.xml文件?

分类: 365提款超过7天 时间: 2025-07-02 18:33:56 作者: admin 阅读: 9777 点赞: 546
在哪里放置struts.xml文件?

我来晚了,我们可以在Web应用程序的类路径中的任何目录中配置struts.xml文件,但是需要使用web.xml中过滤器配置的“config”init参数提供位置,如下所示,如果我的struts.xml文件在“/com/resources/”目录中。

action

org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

config

struts-default.xml,struts-plugin.xml,/com/resources/struts.xml

如果我们不提供一个配置初始化参数,struts2默认会采用三个值“struts-default.xml,struts-plugin.xml,struts.xml”,你可以查看下面的struts2 Dispatcher类代码,它将这三个文件配置到配置管理器中。

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));

}

相关推荐