即使未定义<welcome-file-list>,index.jsp文件也会打开

Raf*_*sin 7 java eclipse jsp tomcat7

我在Eclipse Luna中编写了一个简单的动态Web项目.在web.xml页面中,我删除了默认welcome-file-list标记.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" 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">
  <display-name>indextest</display-name>
</web-app>
Run Code Online (Sandbox Code Playgroud)

但是,即使我从中移除了标记,网址http:// localhost:8080/indextest /仍指向index.jsp"WEB-INF"下.它是如何指向页面的?welcome-file-listweb.xmlindex.jspwelcome-file-listweb.xml

Pao*_*f76 4

如果您使用的是 Tomcat 7 实例,并且未指定welcome-file-list,则容器 (tomcat) 会查找其默认值,即 Tomcat 实例中的 /conf/web.xml 中。

这些是:

<welcome-file-list> 
    <welcome-file>index.html</welcome-file> 
    <welcome-file>index.htm</welcome-file>     
    <welcome-file>index.jsp</welcome-file> 
</welcome-file-list>
Run Code Online (Sandbox Code Playgroud)

我建议不要更改 tomcat 默认值中的任何内容,因为您的 Web 应用程序不应该依赖于运行它的容器。相反,您应该在自己的 web.xml 中定义自己的欢迎文件列表。希望这可以帮助!