我写了一个带有登录页面和注册页面的小型struts应用程序。 如果我登录,我会获得成功页面。如果我注册,我将检查密码并确认密码fileds如果匹配我得到一个成功页面其他失败页面。
我没有使用任何数据库。我写了所需的Form Beans,Action Classes of the。
在struts-config.xml
中,<struts-config>
标记显示错误:
“元素类型”struts-config“的内容必须匹配 “(数据源?,形豆?,全球转发?,动作映射?)“
如何解决此问题?我使用Eclipse作为我的IDE。
答案 0 :(得分:2)
是的,struts-config.xml
根据架构无效,但是当应用正常工作时,它只是一个验证问题。要扩展为什么它在子元素的顺序的上下文中无效 - 如果验证者告诉你...
元素类型“struts-config”的内容必须匹配 “(数据源?,形豆?,全球转发?,动作映射?“)
......那意味着,例如(简化示例):
<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
答案 1 :(得分:1)
您的struts-config.xml文件无效。
Struts-config.xml是一个XML文件,因此可以针对DTD或XML-Schema进行验证。
您在Eclipse中看到的错误是struts-config.xml文件针对其DTD进行验证并且验证失败的结果。很可能是期望你的标签按特定的顺序排列而你没有那样写,你添加了DTD中没有指定的标签,你拼错了一些标签等。
查看struts-config DTD,然后在struts-config.xml文件中查看它们的不同之处。
P.S。有更多版本的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
答案 2 :(得分:0)
我正在使用struts-config_1_3.dtd
。在struts-config.xml
中添加<global-forwards>
标记时,在struts-config.xml
中也遇到了相同的错误。
(“元素类型“ struts-config”的内容必须匹配 “((数据源?,form-beans?,global-forwards?,action-mapping?)”)
我在<global-forwards>
标记之后添加了<action-mapping>
标记,因为它引发了错误。
正如错误说明所言,标记的顺序应为
<datasource></datasource>
<form-beans></form-beans>
<global-forwards></global-forwards>
<action-mapping></action-mapping>
因此,我在<global-forwards>
之前更改了<action-mapping>
。它对我有用。
希望此信息对某人有所帮助。
答案 3 :(得分:-1)
元素的顺序很重要。例如
<form-beans></form-beans>
元素
必须在此之前
<global-forwards></global-forwards>
元素等。