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

标签 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>

但是 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/

相关文章:

java - HttpURLConnection 连接重置错误处理

java - JComponents (Swing) 的二维网格

java - ResourceBundleMessageSource 解决错误

java - _jspService 超出了 65535 字节的限制

java - 在 Java 中使用 Scala 类型(类型不匹配)

java - 如何识别返回的对象是否是在方法执行期间创建的 - Java

android - FileExplorer eclipse 作为 root

java - Eclipse + Jython : Python module not found using one-to-one object factory

eclipse - 如何从 Eclipse 的标记 View 中排除文件/文件夹?

java - 在 Hibernate 中使用 load 而不是 get 时遇到 LazyInitializationException