小编shu*_*hui的帖子

必须声明 web-app 元素(Servlet 4.0)

我尝试使用 Servlet 4.0 命名空间。该应用程序运行良好,但 IDEA 检测到错误:“Element web-app”必须声明”

<?xml version="1.0" encoding="UTF-8"?>
<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_4_0.xsd"
         version="4.0">
    ...
    ...
</web-app>
Run Code Online (Sandbox Code Playgroud)

快照 (我无法直接发布图像。)

当我将版本更改为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">
Run Code Online (Sandbox Code Playgroud)

根据Java EE:Java EE 部署描述符的 XML 模式# 使用 Java EE 模式

所有 Java EE 7 和更高版本的部署描述符模式共享命名空间http://xmlns.jcp.org/xml/ns/javaee/。每个模式文档都包含一个版本属性,其中包含规范的版本。例如,Servlet 规范的 XML 模式文档包含版本属性值“3.1”,与规范的特定版本以及模式文档本身有关。

version="4.0"支持吗?我使用 IntelliJ IDEA 2017.2.5 + javax.servlet-api 4.0 + Apache Tomcat v9.0.1。


更新:我找到了 web.xml 的示例(在apache-tomcat-9.0.1/webapps/examples/WEB-INF/web.xml):

<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_4_0.xsd"
  version="4.0" …
Run Code Online (Sandbox Code Playgroud)

web.xml servlets servlet-4 jakarta-ee

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

jakarta-ee ×1

servlet-4 ×1

servlets ×1

web.xml ×1