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.
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
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
The elements' order matter. For example
<form-beans></form-beans>
element
must be before
<global-forwards></global-forwards>
element etc.
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.
精彩评论