【问题标题】:The content of element type “struts-config” must match “(datasource?,form-beans?元素类型“struts-config”的内容必须匹配“(datasource?,form-b​​eans?
【发布时间】:2011-07-07 00:42:39
【问题描述】:

我编写了一个带有登录页面和注册页面的小型 struts 应用程序。 如果我登录,我会得到一个成功页面。如果我注册,我将检查密码并确认密码文件,如果它们匹配我会得到一个成功页面,否则失败页面。

我没有使用任何数据库。我写了所需的Form Beans,那些Action Classes。

struts-config.xml 中,<struts-config> 标记处显示错误:

"元素类型“struts-config”的内容必须匹配 “(datasource?,form-b​​eans?,global-forwards?,action-mapping?)”

如何解决这个问题?我使用 Eclipse 作为我的 IDE。

【问题讨论】:

    标签: java eclipse struts dtd struts-config


    【解决方案1】:

    是的,根据架构,struts-config.xml 无效,但由于应用程序正在运行,这只是一个验证问题。展开为什么它在子元素的顺序的上下文中是无效的 - 如果验证器告诉你......

    元素类型“struts-config”的内容必须匹配 “(datasource?,form-b​​eans?,global-forwards?,action-mapping?”)

    ...那么这意味着例如(为简洁起见减少示例):

    <struts-config>
      <datasource>...</datasource>
      <form-beans>...</form-beans>
      <global-forwards>...</global-forwards>
      <action-mapping>...</action-mapping>
    </struts-config>
    

    ... 是模式的有效实现,而例如...

    <struts-config>
      <datasource>...</datasource>
      <global-forwards>...</global-forwards>
      <form-beans>...</form-beans>
      <action-mapping>...</action-mapping>
    </struts-config>
    

    ...不是。顺便说一句,这是因为Struts 1.0 DTD in question 说...

    <!ELEMENT struts-config (data-sources?,form-beans?,global-forwards?,action-mappings?)>
    

    ...因此需要一定的子元素顺序。这不是 DTD 作者无意中所做的事情,而是由于以下事实:

    在 DTD 中声明具有出现约束的无序列表将 通常会导致冗长或复杂的声明。 1

    【讨论】:

      【解决方案2】:

      您的 struts-config.xml 文件无效。

      Struts-config.xml 是一个 XML 文件,因此可以根据 DTDXML-Schema 进行验证。

      您在 Eclipse 中看到的错误是根据其 DTD 验证 struts-config.xml 文件并且验证失败的结果。很可能它希望您的标签按特定顺序排列,而您没有那样写它们,您添加了 DTD 中未指定的标签,您拼错了一些标签等。

      查看 struts-config DTD,然后查看您的 struts-config.xml 文件以了解它们的不同之处。

      附: DTD 有更多版本,因此请确保您选择的是正确的版本。

      http://struts.apache.org/dtds/struts-config_1_0.dtd
      http://struts.apache.org/dtds/struts-config_1_1.dtd
      http://struts.apache.org/dtds/struts-config_1_2.dtd
      http://struts.apache.org/dtds/struts-config_1_3.dtd
      http://struts.apache.org/dtds/struts-config_1_4.dtd

      【讨论】:

        【解决方案3】:

        元素的顺序很重要。例如 &lt;form-beans&gt;&lt;/form-beans&gt;元素 必须在之前 &lt;global-forwards&gt;&lt;/global-forwards&gt;元素等

        【讨论】:

          【解决方案4】:

          我正在使用struts-config_1_3.dtd。当我在struts-config.xml 中添加&lt;global-forwards&gt; 标签时,我在struts-config.xml 中也遇到了同样的错误。

          ("元素类型“struts-config”的内容必须匹配 “(datasource?,form-b​​eans?,global-forwards?,action-mapping?)”)

          我在&lt;action-mapping&gt; 标签之后添加了&lt;global-forwards&gt; 标签,因为它会抛出错误。 正如错误描述所说,标签的顺序应该是

          <datasource></datasource>
          
          <form-beans></form-beans>
          
          <global-forwards></global-forwards>
          
          <action-mapping></action-mapping>
          

          所以我在&lt;action-mapping&gt; 之前更改了我的&lt;global-forwards&gt;。它对我有用。

          希望这些信息对某人有所帮助。

          【讨论】:

            猜你喜欢
            • 2017-03-22
            • 1970-01-01
            • 1970-01-01
            • 2012-09-10
            • 2015-06-26
            • 2017-04-06
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多