struts启动错误

公告:
[论坛活动] Bambook程序达人大赛,打造个性电子书,赢取60万大奖[意见反馈][官方博客]   完全解决struts启动时报错:The content of element type "struts-config" must match "(data-sources?,form-beans?,global-exceptions?,global-forwards?,action-mappings?,controller?,message-resources* 收藏
最近新建一个项目,发现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()

view plaincopy to clipboardprint?
01.if (configDigester != null) {  
02.            return (configDigester);  
03.        }  
04. 
05.        // Create a new Digester instance with standard capabilities  
06.        configDigester = new Digester();  
07.        configDigester.setNamespaceAware(true);  
08.        configDigester.setValidating(this.isValidating());//注意此处!!!  
09.        configDigester.setUseContextClassLoader(true);  
10.        configDigester.addRuleSet(new ConfigRuleSet());  
11. 
12.        for (int i = 0; i < registrations.length; i += 2) {  
13.            URL url = this.getClass().getResource(registrations[i + 1]);  
14. 
15.            if (url != null) {  
16.                configDigester.register(registrations[i], url.toString());  
17.            }  
18.        }  
19. 
20.        this.addRuleSets(); 
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();

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

view plaincopy to clipboardprint?
01.private boolean isValidating() {  
02.       boolean validating = true;  
03.       String value = getServletConfig().getInitParameter("validating");  
04. 
05.       if ("false".equalsIgnoreCase(value) || "no".equalsIgnoreCase(value)  
06.           || "n".equalsIgnoreCase(value) || "0".equalsIgnoreCase(value)) {  
07.           validating = false;  
08.       }  
09. 
10.       return validating;  
11.   } 
 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的地方加上

view plaincopy to clipboardprint?
01.<init-param>  
02.            <param-name>validating</param-name>  
03.            <param-value>false</param-value>  
04.        </init-param> 
<init-param>
   <param-name>validating</param-name>
   <param-value>false</param-value>
  </init-param> 

启动服务器,果然搞定!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值