創建動態 Web 項目時,向導最後一步有 **「Generate web.xml deployment descriptor」** 選項,默認**未勾選**(Eclipse 3.7+ / Servlet 3.0+ 支持註解配置,web.xml 非必需)。若未勾選,項目不會自動生成 `WEB-INF/web.xml`。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xmlns="https://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="https://xmlns.jcp.org/xml/ns/javaee
https://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<display-name>MyWebApp</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
現代開發推薦**無 web.xml 純註解配置**:
僅在需兼容舊容器、複雜安全約束、JNDI 數據源等場景才需保留 `web.xml`。