Eclipse 抱怨 Web 应用程序属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6636983/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 20:17:24  来源:igfitidea点击:

Eclipse complaining about web-app attributes

eclipsejakarta-ee

提问by Mark Kadlec

My web-app declaration in my web.xml is:

我的 web.xml 中的 web-app 声明是:

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

Eclipse 抱怨所有 4 个属性,这里是一个 Eclipse 抱怨:

Attribute "version" must be declared for element type "web-app"

Why is Eclipse complaining about these attributes? Am I doing something wrong here?

为什么 Eclipse 会抱怨这些属性?我在这里做错了吗?

回答by Ondrej Tokar

Remove the DOCTYPE line, that is what the xsd is meant to replace. I had the same issue and only this had worked.

删除 DOCTYPE 行,这就是 xsd 要替换的内容。我有同样的问题,只有这个有效。

回答by nachoorme

Try to put in this way:

尝试以这种方式放置:

<web-app  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"   version="2.4" >

Eclipse validator is very strict with the order.

Eclipse 验证器对命令非常严格。

回答by Arif Hossain

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"

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

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".

另外,将版本设置为"3.0".

回答by mannedear

I changed the declaration from

我改变了声明

http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd">

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

到以下内容,它就像魅力一样。现在 web.xml 中没有显示错误

http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

回答by Anastasia Abramova

Didn't you forget this row in your xml file?:

你没有忘记你的 xml 文件中的这一行吗?:

    <?xml version="1.0" encoding="ISO-8859-1"?>

Your file should start like this:

你的文件应该像这样开始:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">

If it doesn't work clean and refresh your project.

如果它不起作用干净并刷新您的项目。

回答by Chiranjib

Refer to thisoracle.com link to know what all were announced with Java EE 7 (assuming that is what we're working with). The link states

请参阅oracle.com 链接以了解 Java EE 7 发布的所有内容(假设这是我们正在使用的内容)。链接状态

All new schemas are in the http://xmlns.jcp.org/xml/ns/javaee/namespace.

所有新模式都在http://xmlns.jcp.org/xml/ns/javaee/命名空间中。

The namespace java.sunhas not become java.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.

命名空间java.sun没有成为java.oracle,而是由Java 社区进程 (JCP)保留。因此,所有命名空间都应该指向 xmlns.jcp.org,正如 Java EE 7 文档所指出的那样。

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.

现在,当我们部署一个 Web 应用程序时(因此需要定义一个 web.xml),首先我们必须知道我们打算做什么。

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.

假设我们正在使用 Apache Tomcat V8。如果我们阅读这里的文档,我们就会知道它与 Servlet 3.1 捆绑在一起。所以,我更喜欢 Servlet 3.1 的实现,只是为了保持最新状态。

Now all that being said, this is the declaration I would have

说了这么多,这就是我的宣言

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

</web-app>

Hope this answers the question.

希望这能回答这个问题。

回答by Sachin

Just remove the DOCTYPE. And its works fine.

只需删除 DOCTYPE。它的工作正常。