gutch
gutch

Reputation: 7139

Why does Tomcat 7 append index.html to URLs when Tomcat 6 does not?

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?

Upvotes: 3

Views: 2201

Answers (2)

ryan
ryan

Reputation: 97

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>

Upvotes: 0

gutch
gutch

Reputation: 7139

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.

Upvotes: 4

Related Questions