我在 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>
但是 url http://localhost:8080/indextest/即使在我从 web.xml
中删除了标签 welcome-file-list
之后,仍然指向“WEB-INF”下的 index.jsp
. web.xml
中没有welcome-file-list
是如何指向index.jsp
页面的?
最佳答案
如果您使用的是 Tomcat 7 实例,并且没有指定欢迎文件列表,则容器 (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>
我建议不要更改 tomcat 默认值中的任何内容,因为您的 Web 应用程序不应依赖于运行它的容器。相反,您应该在自己的 web.xml 中定义自己的欢迎文件列表。 希望这对您有所帮助!
关于java - 即使未定义 <welcome-file-list> 也会打开 index.jsp 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32347743/