configure tomcat to serv index.html

6.7k Views Asked by At

I'm looking for a way to get tomcat to show an index.html automatically for my app in one of the sub directories.

When I try to access

http://mydomain.tld/myapp/docs
http://mydomain.tld/myapp/docs/

I get a "404 file not found" error. But when I load

http://mydomain.tld/myapp/docs/index.html

it works fine.

My current web.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                             http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <display-name>Foo</display-name>
    <description>Bar</description>

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



    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>/docs/*</url-pattern>
    </servlet-mapping>

</web-app>

What am I missing here? Why won't tomcat honer the <welcom-file-list />?

Edit

Weirdly this behaves correctly if I create an app which has no web.xml or servlets (just static content). So tomcat does know how to do this.

1

There are 1 best solutions below

2
On

You need to include the subdirectory:

<welcome-file>docs/index.html</welcome-file>