Eclipse 抱怨 Web 应用程序属性

发布于 2024-11-19 06:38:58 字数 493 浏览 2 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

一个人的夜不怕黑 2024-11-26 06:38:58

删除 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.

满天都是小星星 2024-11-26 06:38:58

我也有同样的问题。我尝试了不同的架构位置,它对我有用。而不是

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

怪我太投入 2024-11-26 06:38:58

尝试这样表述:

<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 验证器对顺序非常严格。

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.

划一舟意中人 2024-11-26 06:38:58

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

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

你的文件应该这样开始:

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

如果它不起作用,请清理并刷新你的项目。

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

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

雨夜星沙 2024-11-26 06:38:58

我更改了声明

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

与之呼应 2024-11-26 06:38:58

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

所有新架构均位于 http://xmlns.jcp.org/xml/ns 中/javaee/
命名空间。

命名空间 java.sun 并没有变成 java.oracle,而是被 Java 社区流程 (JCP)。因此,所有命名空间都应指向 xmlns.jcp.org,Java EE 7 文档也指出了这一点。

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

比如说,我们正在使用 Apache Tomcat V8。如果我们阅读此处的文档,我们就会知道它捆绑了 Servlet 3.1 。因此,我更喜欢 Servlet 3.1 的实现,只是为了保持最新状态(如果不是别的)。

话虽如此,这就是我想要的声明,

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

希望这能回答问题。

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

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

The namespace java.sun has 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.

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

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

彼岸花ソ最美的依靠 2024-11-26 06:38:58

我所做的就是将所有 xsd 和架构位置声明替换为以下声明,

<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_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
id="WebApp_ID" version="3.0">

它开始正常工作。

参考: 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,

<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_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
id="WebApp_ID" version="3.0">

It started working fine.

reference: https://docs.oracle.com/cd/E24329_01/web.1211/e21049/web_xml.htm#WBAPP502

大姐,你呐 2024-11-26 06:38:58

只需删除 DOCTYPE 即可。而且效果很好。

Just remove the DOCTYPE. And its works fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文