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

发布于 2024-10-20 09:50:25 字数 389 浏览 2 评论 0原文

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

我没有使用任何数据库。我编写了所需的 Form Beans、其中的 Action 类。

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

“元素类型“struts-config”的内容必须匹配 “(数据源?,form-b​​eans?,全局转发?,动作映射?)”

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

I wrote a small struts application with a login page and registration page.
If I login I get a success page. If i register, i will check the password and confirm password fileds if they match i get a success page else failure page.

I did not use any database. I wrote the required Form Beans, Action Classes of those.

In struts-config.xml it is showing an error at the <struts-config> tag:

"The content of element type “struts-config” must match
“(datasource?,form-beans?,global-forwards?,action-mapping?)"

How to resolve this problem? I am using Eclipse as my IDE.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

以酷 2024-10-27 09:50:25

是的,根据架构,struts-config.xml 无效,但随着应用程序正在运行,这只是一个验证问题。要详细说明为什么它在子元素的顺序的上下文中无效 - 如果验证器告诉您......

元素类型“struts-config”的内容必须匹配
“(数据源?,form-b​​eans?,全局转发?,动作映射?”)

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

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

...是模式的有效实现,而eg . ..

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

...不是。顺便说一下,这是由于 有问题的 Struts 1.0 DTD 说...

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

...并且要求子元素具有一定的顺序,这不是 DTD 作者无意中所做的事情,而是由于以下事实:

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

Yes, the struts-config.xml is invalid according to the schema, but as the app is working, it's only a validation issue. To expand on why it is invalid in the context of the order of the child elements - If the validator is telling you that...

The content of element type “struts-config” must match
“(datasource?,form-beans?,global-forwards?,action-mapping?")

...then that means that e.g. (reduced examples for brevity):

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

...is a valid implementation of the schema, while e.g. ...

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

...is not. This, by the way, is due to the fact that the Struts 1.0 DTD in question says...

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

...and by that demands a certain order of child elements. This is not something that the DTD authors do inadvertently, but due to fact that:

Declaring unordered lists with occurrence constraints in DTD will
often result in long or complicated looking declarations. 1

不一样的天空 2024-10-27 09:50:25

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

Struts-config.xml 是一个 XML 文件,因此可以针对 DTDXML-Schema。

您在 Eclipse 中看到的错误是由于 struts-config.xml 文件根据其 DTD 进行验证而验证失败造成的。最有可能的是,它期望您的标签按特定顺序排列,而您没有那样编写它们,您添加了 DTD 中未指定的标签,您拼写错误了一些标签等。

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

PS: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

Your struts-config.xml file is invalid.

Struts-config.xml is an XML file and as such can be validated against a DTD or an XML-Schema.

The error you are seeing in Eclipse is a result of the struts-config.xml file being validated against its DTD and the validation fails. Most likely it is expecting your tags to be in a specific order and you didn't write them that way, you added tags that are not specified in the DTD, you misspelled some tag etc.

Look at the struts-config DTD and then at your struts-config.xml file to see where they differ.

P.S. there are more versions of the DTD so make sure you are looking at the right one.

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

神妖 2024-10-27 09:50:25

元素的顺序很重要。例如
元素
必须在之前
元素等。

The elements' order matter. For example
<form-beans></form-beans> element
must be before
<global-forwards></global-forwards> element etc.

安稳善良 2024-10-27 09:50:25

我正在使用 struts-config_1_3.dtd。当我在 struts-config.xml 中添加 标记时,我在 struts-config.xml 中也遇到了同样的错误。

("元素类型“struts-config”的内容必须匹配
“(数据源?,form-b​​eans?,全局转发?,动作映射?)”)

我在 之后添加了 标签code> 标记,因此它抛出错误。
正如错误描述所述,标签的顺序应该是

<datasource></datasource>

<form-beans></form-beans>

<global-forwards></global-forwards>

<action-mapping></action-mapping>

所以我在 之前更改了 。这对我有用。

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

I am using struts-config_1_3.dtd. I also got the same error in struts-config.xml when I added <global-forwards> tag in struts-config.xml.

("The content of element type “struts-config” must match
“(datasource?,form-beans?,global-forwards?,action-mapping?)")

I added <global-forwards> tag after <action-mapping> tag, because of that it was throwing error.
As the error description says, the order of the tags should be

<datasource></datasource>

<form-beans></form-beans>

<global-forwards></global-forwards>

<action-mapping></action-mapping>

So i changed my <global-forwards> before <action-mapping>. And it worked for me.

Hope this information help someone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文