【问题标题】:Why does Tomcat 7 append index.html to URLs when Tomcat 6 does not?为什么 Tomcat 7 将 index.html 附加到 URL,而 Tomcat 6 没有?
【发布时间】:2012-02-24 20:56:23
【问题描述】:

我正在尝试将现有 Java Web 应用程序从 Tomcat 6 (6.0.32) 升级到 Tomcat 7 (7.0.23)。它是用 Spring MVC 和 Tiles 构建的。

大多数应用程序在 Tomcat 7 中运行良好,无需更改代码或配置。一个问题是主页坏了:Tomcat 7 显示我们的标准 404 页面而不是主页。网站上的其他页面看起来还不错。

日志显示问题在于某些东西(可能是 Tomcat)正在将 index.html 附加到主页请求。换句话说,当我导航到 URL http://localhost/ 时,Web 应用程序将其视为 http://localhost/index.html。这不起作用,因为我们没有 index.html,主页是动态生成的,并且应该由 Spring MVC 处理。

一些日志说明了这个问题。这些是点击主页时调试日志的前几行:

Tomcat 6

17:42:00.768 [TP-Processor3] DEBUG o.s.s.web.util.AntPathRequestMatcher     - Checking match of request : '/'; against '/ws/**'
17:42:00.769 [TP-Processor3] DEBUG o.s.security.web.FilterChainProxy        - / at position 1 of 11 in additional filter chain; firing Filter: 'ChannelProcessingFilter'
17:42:00.769 [TP-Processor3] DEBUG o.s.s.web.util.AntPathRequestMatcher     - Checking match of request : '/'; against '/login'
17:42:00.769 [TP-Processor3] DEBUG o.s.s.web.util.AntPathRequestMatcher     - Checking match of request : '/'; against '/login-process'
17:42:00.769 [TP-Processor3] DEBUG o.s.s.web.util.AntPathRequestMatcher     - Checking match of request : '/'; against '/'
17:42:00.769 [TP-Processor3] DEBUG o.s.s.w.a.c.ChannelProcessingFilter      - Request: FilterInvocation: URL: /; ConfigAttributes: [REQUIRES_INSECURE_CHANNEL]
17:42:00.770 [TP-Processor3] DEBUG o.s.security.web.FilterChainProxy        - / at position 2 of 11 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'

Tomcat 7

17:39:47.462 [ajp-bio-18009-exec-2] DEBUG o.s.s.web.util.AntPathRequestMatcher - Checking match of request : '/index.html'; against '/ws/**'
17:39:47.462 [ajp-bio-18009-exec-2] DEBUG o.s.security.web.FilterChainProxy - /index.html at position 1 of 11 in additional filter chain; firing Filter: 'ChannelProcessingFilter'
17:39:47.462 [ajp-bio-18009-exec-2] DEBUG o.s.s.web.util.AntPathRequestMatcher - Checking match of request : '/index.html'; against '/login'
17:39:47.462 [ajp-bio-18009-exec-2] DEBUG o.s.s.web.util.AntPathRequestMatcher - Checking match of request : '/index.html'; against '/login-process'
17:39:47.462 [ajp-bio-18009-exec-2] DEBUG o.s.s.web.util.AntPathRequestMatcher - Checking match of request : '/index.html'; against '/'
17:39:47.462 [ajp-bio-18009-exec-2] DEBUG o.s.security.web.FilterChainProxy - /index.html at position 2 of 11 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'

据我所知,Tomcat 6 和 Tomcat 7 的配置方式相同,允许在版本之间更改一些默认配置。我仔细检查了<welcome-file-list> 在每一个中都完全相同。

那么是什么原因导致 index.html 被附加到 Tomcat 7 中的 URL 中?

【问题讨论】:

    标签: java tomcat spring-mvc tomcat7


    【解决方案1】:

    答案是从 WAR 的 web.xml 中的 <welcome-file-list> 元素中删除 index.html。即:

    损坏的 web.xml:

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
    

    工作 web.xml:

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    

    真正奇怪的是,将 index.jsp 留在其中并不会导致 Tomcat 7 将 http://localhost/ 视为 http://localhost/index.jsp — 它只是index.html有问题。

    所以它是固定的,但是,真的,我不知道为什么会这样。

    【讨论】:

      【解决方案2】:

      我遇到了几乎相同的问题,我使用嵌入式 tomcat 部署 Web 应用程序。我将文件“aaa.html”放入欢迎文件列表中。但是当我运行tomcat并通过url“http://localhost:8080/appname/”访问webapp时,tomcat将尝试返回index.jsp(也存在于我的应用程序中)而不是aaa.html。为了显示我指定的欢迎页面 aaa.html,我必须添加另一个 index.html 并让 index.html 重定向到 aaa.html,如下所示:

      <welcome-file-list>
          <welcome-file>index.html</welcome-file>   <-- added for tomcat 7
          <welcome-file>aaa.html</welcome-file>
      </welcome-file-list>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-04-03
        • 2022-01-01
        • 2012-02-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-31
        相关资源
        最近更新 更多