Java 在 web.xml 中发现以元素“display-name”开头的无效内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3982403/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Invalid content was found starting with element 'display-name' in web.xml
提问by juny fan
I am using Eclipse Helios Release. Eclipse xml validator doesn't like the display-name
element under <servlet>
in my web.xml. Here's the relevant part:
我正在使用 Eclipse Helios Release。Eclipse xml 验证器不喜欢我的 web.xmldisplay-name
下的元素<servlet>
。这是相关部分:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID"
version="2.5">
<display-name>PropTax</display-name>
<servlet>
<servlet-name>PropTax</servlet-name>
<display-name>PropTax</display-name>
<servlet-class>org.slco.treasurer.propertytax.servlet.PropTax</servlet-class>
</servlet>
(...)
If I remove display-name element then there is no error anymore. If I understand correctly 2.5 is the right schema to support display-name, and even context help under the editor will list display-name as part of choice.
如果我删除 display-name 元素,则不再有错误。如果我理解正确,2.5 是支持显示名称的正确模式,甚至编辑器下的上下文帮助也会将显示名称列为选择的一部分。
Could anyone help me here?
有人可以在这里帮助我吗?
Error message from Eclipse validator:
来自 Eclipse 验证器的错误消息:
cvc-complex-type.2.4.a: Invalid content was found starting with element 'display-name'. One of '{"http://java.sun.com/xml/ns/javaee":servlet-class, "http://java.sun.com/xml/ns/javaee":jsp-file}' is expected. web.xml /PropTax/WebContent/WEB-INF line 6 XML Problem
回答by dty
You need to use the '101010' button to quote your XML for it to be readable.
您需要使用“101010”按钮来引用您的 XML 以使其可读。
However, according to the XSD you referenced, a servlet definition (servlet
tag) needs to have the description stuff (including display-name
) before the servlet-name
. Given the error you've posted, I suspect you've got servlet-name
followed by display-name
. However, it's hard to tell without seeing the XML well formatted.
但是,根据您引用的 XSD,servlet 定义(servlet
标记)需要display-name
在servlet-name
. 鉴于您发布的错误,我怀疑您已经servlet-name
关注了display-name
. 但是,如果没有看到格式良好的 XML,就很难判断。
回答by user959740
Move "display-name" as the first element under "servlet" tag, the validation error should go away.
将“显示名称”作为“servlet”标签下的第一个元素,验证错误应该消失。
<servlet>
<display-name>PropTax</display-name>
<servlet-name>PropTax</servlet-name>
<servlet-class>org.slco.treasurer.propertytax.servlet.PropTax</servlet-class>
</servlet>
回答by ckl
Comment out the warning/error (or all) elements from servlet tab, and use eclipse web.xml Design editor to "Add Child" for "display-name". Eclipse WEB.XML design editor will automatically update the XML file with validator arranged order.
从 servlet 选项卡中注释掉警告/错误(或所有)元素,并使用 eclipse web.xml 设计编辑器为“显示名称”“添加子项”。Eclipse WEB.XML 设计编辑器将按照验证器排列的顺序自动更新 XML 文件。
回答by Avnish
You have to put the tag display-name first.
您必须首先放置标签显示名称。
<servlet>
<display-name>PropTax</display-name>
<servlet-name>PropTax</servlet-name>
<servlet-class>org.slco.treasurer.propertytax.servlet.PropTax</servlet-class>