Eclipse 抱怨 Web 应用程序属性
我的 web.xml 中的 Web 应用程序声明是:
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
Eclipse 抱怨所有 4 个属性,这是 Eclipse 的一个抱怨:
Attribute "version" must be declared for element type "web-app"
为什么 Eclipse 抱怨这些属性?我在这里做错了什么吗?
My web-app declaration in my web.xml is:
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
And eclipse complains about all 4 attributes, here is one Eclipse complaint:
Attribute "version" must be declared for element type "web-app"
Why is Eclipse complaining about these attributes? Am I doing something wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
删除 DOCTYPE 行,这就是 xsd 想要替换的内容。我遇到了同样的问题,只有这个有效。
Remove the DOCTYPE line, that is what the xsd is meant to replace. I had the same issue and only this had worked.
我也有同样的问题。我尝试了不同的架构位置,它对我有用。而不是
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
尝试使用此
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd
另外,将版本设置为
“3.0”
。I had the same problem. I tried a different schema location and it worked for me. Instead of
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
try using this
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd
Also, set the version as
"3.0"
.尝试这样表述:
Eclipse 验证器对顺序非常严格。
Try to put in this way:
Eclipse validator is very strict with the order.
你没有忘记 xml 文件中的这一行吗?:
你的文件应该这样开始:
如果它不起作用,请清理并刷新你的项目。
Didn't you forget this row in your xml file?:
Your file should start like this:
If it doesn't work clean and refresh your project.
我更改了声明
http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd">
到以下内容,它就像魅力一样工作。现在 web.xml 中没有显示错误
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
I changed the declaration from
http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd">
to the following and it worked like charm. Now no errors shown in web.xml
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
请参阅此 oracle.com 链接了解 Java EE 7 发布的所有内容(假设这就是我们正在使用的内容)。链接指出
命名空间
java.sun
并没有变成java.oracle
,而是被 Java 社区流程 (JCP)。因此,所有命名空间都应指向 xmlns.jcp.org,Java EE 7 文档也指出了这一点。现在,当我们部署 Web 应用程序(因此需要定义 web.xml)时,首先我们必须知道我们打算做什么。
比如说,我们正在使用 Apache Tomcat V8。如果我们阅读此处的文档,我们就会知道它捆绑了 Servlet 3.1 。因此,我更喜欢 Servlet 3.1 的实现,只是为了保持最新状态(如果不是别的)。
话虽如此,这就是我想要的声明,
希望这能回答问题。
Refer to this oracle.com link to know what all were announced with Java EE 7 (assuming that is what we're working with). The link states
The namespace
java.sun
has not becomejava.oracle
, instead it has been retained by The Java Community Process (JCP). Hence all namespaces should point to xmlns.jcp.org, as is also pointed out by Java EE 7 docs.Now, when we are deploying a web application (and hence the need to define a web.xml), first we have to know what we intend to do.
Say, we are working with Apache Tomcat V8. If we read the docs here, we get to know that it comes with Servlet 3.1 bundled. So, I would prefer an implementation of Servlet 3.1, just to stay up to date if not anything else.
Now all that being said, this is the declaration I would have
Hope this answers the question.
我所做的就是将所有 xsd 和架构位置声明替换为以下声明,
它开始正常工作。
参考: https://docs.oracle.com/cd/E24329_01/web.1211/e21049/web_xml.htm#WBAPP502
All I have done is, replaced all the xsd and schema location declarations with the below one,
It started working fine.
reference: https://docs.oracle.com/cd/E24329_01/web.1211/e21049/web_xml.htm#WBAPP502
只需删除 DOCTYPE 即可。而且效果很好。
Just remove the DOCTYPE. And its works fine.