【问题标题】:index.jsp file opens even when the <welcome-file-list> is not defined即使未定义 <welcome-file-list> 也会打开 index.jsp 文件
【发布时间】:2015-11-27 15:24:57
【问题描述】:

我在 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>

但即使我从web.xml 中删除了标签welcome-file-list,URL http://localhost:8080/indextest/ 仍然指向“WEB-INF”下的index.jsp。尽管welcome-file-listweb.xml 中不存在,但它如何指向index.jsp 页面?

【问题讨论】:

  • 你用的是什么服务器?
  • 可能是保存在浏览器的cookies中,删除重试。或者只是清理你的tomcat工作目录,有时也会产生问题。
  • 我正在使用 Tomcat v7.0 >>> @Paolof76
  • 好的,我知道这个问题......让我们在帖子中解释一下
  • 嘿@RafafTahsin,我还添加了您使用tomcat 7的信息,很高兴知道...

标签: java eclipse jsp tomcat7


【解决方案1】:

如果您使用的是 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 中定义自己的欢迎文件列表。 希望这会有所帮助!

【讨论】:

    【解决方案2】:

    如果没有提供欢迎列表,则容器将尝试按定义的顺序加载以下文件:

    1. index.html
    2. index.htm
    3. index.jsp

    更新: 关于tomcat

    如果应用程序中没有提供 web.xml,则将 Tomcat 的默认 web.xml($CATALINA_HOME/conf/web.xml) 提供给应用程序。这个部署描述符有以下几行:

    <!-- -->
    <!-- If you define welcome files in your own application's web.xml -->
    <!-- deployment descriptor, that list *replaces* the list configured -->
    <!-- here, so be sure to include any of the default values that you wish -->
    <!-- to use within your application. -->
    
    <welcome-file-list> 
        <welcome-file>index.html</welcome-file> 
        <welcome-file>index.htm</welcome-file>     
        <welcome-file>index.jsp</welcome-file> 
    </welcome-file-list>
    

    这就是默认显示 index.jsp 的原因

    更新来源:https://stackoverflow.com/a/17247947/1129313

    【讨论】:

      【解决方案3】:

      如果您更改文件名,默认文件将调用index.jsp 然后它将找不到index.jsp,您可以得到预期的结果。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-09-18
        • 1970-01-01
        • 2016-11-28
        • 2012-11-07
        • 1970-01-01
        • 2017-04-20
        • 1970-01-01
        相关资源
        最近更新 更多