【问题标题】:Why does struts.xml have a configuration error?为什么struts.xml有配置错误?
【发布时间】:2015-10-26 15:42:41
【问题描述】:

我在文件 struts.xml 中收到配置错误

错误

The content of element type "package" must match "
(result-types?,interceptors?,default-interceptor-ref?,
default-action-  ref?,default-class-ref?,global-results?,
global-exception-mappings?,action*)".

错误描述是什么意思?

struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

    <constant name="struts.devMode" value="true" />

    <package name="basicstruts2" extends="struts-default">

        <global-results>
            <result name="securityerror">/securityerror.jsp</result>
            <result name="error">/error.jsp</result>
        </global-results>

        <global-exception-mappings>
            <exception-mapping
                exception="org.apache.struts.register.exceptions.SecurityBreachException"
                result="securityerror" />
            <exception-mapping exception="java.lang.Exception"
                result="error" />
        </global-exception-mappings>

        <interceptors>
            <interceptor-stack name="appDefaultStack">
                <interceptor-ref name="defaultStack">
                    <param name="exception.logEnabled">true</param>
                    <param name="exception.logLevel">ERROR</param>
                </interceptor-ref>
            </interceptor-stack>
        </interceptors>

        <default-interceptor-ref name="appDefaultStack" />

        <action name="actionspecificexception" class="org.apache.struts.register.action.Register"
            method="throwSecurityException">
            <exception-mapping
                exception="org.apache.struts.register.exceptions.SecurityBreachException"
                result="login" />
            <result>/register.jsp</result>
            <result name="login">/login.jsp</result>
        </action>

        <action name="index">
            <result>/index.jsp</result>
        </action>

        <!-- If the URL is hello.action the call the execute method of class HelloWorldAction. 
            If the result returned by the execute method is success render the HelloWorld.jsp -->
        <action name="hello"
            class="org.apache.struts.helloworld.action.HelloWorldAction" method="execute">
            <result name="success">/HelloWorld.jsp</result>
        </action>

        <action name="register" class="org.apache.struts.register.action.Register"
            method="execute">
            <result name="success">/thankyou.jsp</result>
            <result name="input">/register.jsp</result>
        </action>

        <action name="registerInput" class="org.apache.struts.register.action.Register"
            method="input">
            <result name="input">/register.jsp</result>
        </action>

    </package>

</struts>

【问题讨论】:

标签: xml eclipse configuration struts2 struts


【解决方案1】:

错误告诉您package 的内容顺序错误。例如interceptors 必须在global-results 之前。

重新排列元素以匹配消息中显示的顺序。

顺序 in struts.xml 很重要:

  1. 结果类型?
  2. 拦截器?
  3. 默认拦截器引用?
  4. default-action- ref?
  5. 默认类引用?
  6. 全局结果?
  7. 全局异常映射?
  8. 行动*

【讨论】:

  • 我在 Global-Results/Global-Exception-Mappings 之前有一个操作。不得不把它移到底部。
猜你喜欢
  • 1970-01-01
  • 2018-03-30
  • 2013-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-01
  • 2020-01-29
  • 2015-05-03
相关资源
最近更新 更多