从 Java Servlet 4 转换到 Jakarta Servlet 5 时更新 "web.xml"

Updating "web.xml" when transitioning from Java Servlet 4 to Jakarta Servlet 5

我正在将一个简单的 Servlet 从使用 Java Servlet 4 过渡到 Jakarta Servlet 5

我注意到我的 web.xml 文件引用了 4 规范。

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

我希望那些 javaee4 值应该改变。

示例来自 Tomcat

这是我在 web.xml 文件中使用的内容。

<?xml version="1.0" encoding="UTF-8"?>
<web-app
        xmlns = "https://jakarta.ee/xml/ns/jakartaee"
        xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation = "https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"
        version = "5.0"
        metadata-complete = "false"
>
    <display-name> Welcome to Tomcat</display-name>
    <description> Welcome to Tomcat</description>
</web-app>

此示例基于 web.xml 文件,该文件位于与 Tomcat 10 捆绑在一起的 ROOT 网络应用中。0.x.阅读 8.1 Annotations and Pluggability of the Jakarta Servlet 5 spec 部分以决定是否要将 metadata-complete 设置为 truefalse.

Servlet 规范中的示例

另请参阅 14.4.1. A Basic Example of the Jakarta Servlet Specification, Version 5.0 部分中的部署描述符示例 (web.xml),版权所有 (c) 2019、2020 Eclipse Foundation。

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee
         web-app_5_0.xsd"
         version="5.0">

  <display-name>A Simple Application</display-name>

  <context-param>
    <param-name>Webmaster</param-name>
    <param-value>webmaster@example.com</param-value>
  </context-param>

  <servlet>
    <servlet-name>catalog</servlet-name>
    <servlet-class>com.example.CatalogServlet</servlet-class>
    <init-param>
      <param-name>catalog</param-name>
      <param-value>Spring</param-value>
    </init-param>
  </servlet>

  <servlet-mapping>
    <servlet-name>catalog</servlet-name>
    <url-pattern>/catalog/*</url-pattern>
  </servlet-mapping>

  <session-config>
    <session-timeout>30</session-timeout>
  </session-config>

  <mime-mapping>
    <extension>pdf</extension>
    <mime-type>application/pdf</mime-type>
  </mime-mapping>

  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>

  <error-page>
    <error-code>404</error-code>
    <location>/404.html</location>
  </error-page>

</web-app>