为什么 Tomcat 7 将 index.html 附加到 URL,而 Tomcat 6 不附加?

发布于 2025-01-02 02:11:32 字数 2815 浏览 0 评论 0原文

我正在尝试将现有 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/ 时,网络应用程序将其视为 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 配置相同方式,允许在版本之间更改某些默认配置。我已经仔细检查过每个文件中的 是否完全相同。

那么什么可能导致 index.html 被附加到 Tomcat 7 中的 URL 中呢?

I'm attempting to upgrade an existing Java web app from Tomcat 6 (6.0.32) to Tomcat 7 (7.0.23). It's built with Spring MVC and Tiles.

Most of the app runs just fine in Tomcat 7 with no changes to code or configuration. The one problem is that the homepage is broken: Tomcat 7 displays our standard 404 page instead of the homepage. Other pages on the site seem fine.

The logs show that the problem is that something — presumably Tomcat — is appending index.html to the homepage request. In other words, when I navigate to the URL http://localhost/ the web app is treating it as http://localhost/index.html. That doesn't work because we don't have an index.html, the homepage is dynamically generated and is meant to be handled by Spring MVC.

Some logs illustrate the problem. These are the first few lines of the debug log when hitting the homepage:

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'

As far as I can tell, Tomcat 6 and Tomcat 7 are configured in the same way, allowing for changes to some of some of the default configuration between versions. I've doublechecked that the <welcome-file-list> is exactly the same in each one.

So what could be causing index.html to be appended to the URL in Tomcat 7?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

抱着落日 2025-01-09 02:11:32

答案是从 WAR 中 web.xml 的 元素中删除 index.html。 ie:

损坏的 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 有问题。

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

The answer was to remove index.html from the <welcome-file-list> element in web.xml in the WAR. ie:

Broken web.xml:

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

Working web.xml:

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

The really weird thing about this is that leaving index.jsp in there doesn't ever cause Tomcat 7 to treat http://localhost/ as http://localhost/index.jsp — it only has problems with index.html.

So it's fixed but, really, I have no idea why that works.

z祗昰~ 2025-01-09 02:11:32

我遇到了几乎同样的问题,我使用嵌入式tomcat来部署Web应用程序。我将文件“aaa.html”放入欢迎文件列表中。但是当我运行tomcat并通过url“http://localhost:8080/appname/”访问web应用程序时,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>

I met almost the same problem, I use embedded tomcat to deploy a web application. I put a file "aaa.html" into the welcome-file-list. But when I run the tomcat and access the webapp by url "http://localhost:8080/appname/", tomcat will tried to return back the index.jsp (which also exists in my application) instead of aaa.html. In order to show my specified welcome page aaa.html, I have to add another index.html and let index.html redirects to aaa.html, like below:

<welcome-file-list>
    <welcome-file>index.html</welcome-file>   <-- added for tomcat 7
    <welcome-file>aaa.html</welcome-file>
</welcome-file-list>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文