您的位置:首页 > 编程语言 > Java开发

The content of element type "struts-config" must match "(display-name?,description?,data-sources?,fo

2014-06-09 10:31 218 查看
报错信息:

严重: Parse Error at line 58 column 17: The content of element type "struts-config" must match "(display-name?,description?,data-sources?,form-beans?,global-exceptions?,global-forwards?,action-mappings?,controller?,message-resources*,plug-in*)".

org.xml.sax.SAXParseException: The content of element type "struts-config" must match "(display-name?,description?,data-sources?,form-beans?,global-exceptions?,global-forwards?,action-mappings?,controller?,message-resources*,plug-in*)".

问题分析:

解决办法:

The content of element type "struts-config" must match "(data-sources?,form-bean

最近新建一个项目,发现tomcat启动的时候时,控制台一直报告异常信息:

10 12 22 09:49:016,306 ERROR Digester:1463 - Parse Error at line 21 column 17: The content of element type "struts-config" must match "(data-sources?,form-beans?,global-exceptions?,global-forwards?,action-mappings?,controller?,message-resources*,plug-in*)".

org.xml.sax.SAXParseException: The content of element type "struts-config" must match "(data-sources?,form-beans?,global-exceptions?,global-forwards?,action-mappings?,controller?,message-resources*,plug-in*)".

。。。。。。

虽然这不影响系统的运行,但看到每次启动就报这一堆异常信息,心里也很不爽。

在网上搜索了下解决办法,但是大部分都是只有提问,没有结果,或者就是解决办法不管用。于是,下决心自己去解决。认真查看异常信息,发现如下重要信息:

at org.apache.struts.action.ActionServlet.parseModuleConfigFile(ActionServlet.java:738)

at org.apache.struts.action.ActionServlet.initModuleConfig(ActionServlet.java:687)

于是,找到对应源代码:ActionServlet中的方法initConfigDigester()

[c-sharp] view plaincopy

if (configDigester != null) {
return (configDigester);
}

// Create a new Digester instance with standard capabilities
configDigester = new Digester();
configDigester.setNamespaceAware(true);
configDigester.setValidating(this.isValidating());//注意此处!!!
configDigester.setUseContextClassLoader(true);
configDigester.addRuleSet(new ConfigRuleSet());

for (int i = 0; i < registrations.length; i += 2) {
URL url = this.getClass().getResource(registrations[i + 1]);

if (url != null) {
configDigester.register(registrations[i], url.toString());
}
}

this.addRuleSets();

注意标注【注意的代码行】,其调用的代码如下:

[c-sharp] view plaincopy

private boolean isValidating() {
boolean validating = true;
String value = getServletConfig().getInitParameter("validating");

if ("false".equalsIgnoreCase(value) || "no".equalsIgnoreCase(value)
|| "n".equalsIgnoreCase(value) || "0".equalsIgnoreCase(value)) {
validating = false;
}

return validating;
}

分析到此处,大家相信都知道怎么回事了。赶紧前往web.xml配置org.apache.struts.action.ActionServlet的地方加上

[c-sharp] view plaincopy

<init-param>
<param-name>validating</param-name>
<param-value>false</param-value>
</init-param>

启动服务器,果然搞定!

另外还有一个原因:
struts-config.xml配置文件顺序 The content of element type "struts-config" must match

struts-config.xml中的元素有严格的顺序,如果元素的顺序出错,系统会抛出一个错误,描述如下:

The content of element type "struts-config" must match "(display-name?,description?,data-sources?,form-beans?,global-exceptions?,global-forwards?,

action-mappings?,controller?,message-resources*,plug-in*)". [109]

刚看到这个错误,我总以为是某个元素的拼写出了错误,把整个文件仔细检查了一遍,没有发现任何拼写作错误。查了资料才知道,struts-config.xml中的元素有严格的顺序,他们的顺序应该是象下面这个样子:

<struts?config>

<data?sources>

<data?source>

</data?source>

</data?sources>

<form?beans>

<form?bean />

</form?beans>

<global?forwards>

<forward />

</global?forwards>

<action?mappings>

<action/>

</action?mappings>

<controller />

<message?resource />

<plug?in />

</struts?config>

上面的错误提示不是说元素有拼写错误,而是说struts-config.xml必须按照display-name-->description-->datasources-->form-beans-->global-forwards-->action-mappings-->controller-->message_resources-->plug-in的顺序书写。

注意: 节点之间要有换行
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐