How to access index.html file under WEB-INF

7.1k views Asked by At

In my sample web application being built on eclipse I tried placing the index.html file under WEB-INF folder and then updating the deployment descriptor web.xml file as below to load the same on deployment:

<welcome-file>WEB-INF/index.html</welcome-file>

But when I try deploying the web app in Tomcat server it doesn't load the index.html file. However when I move the index.html file directly to the root of the application , i.e. directly under the WebContent folder, the index.html file does get loaded successfully in the browser.

I guess if I have to place the default index.html file under WEB-INF then I need to write a servlet and keep it as <load-on-startup>0</load-on-startup>
in my web.xml file. Otherwise there is no way the Tomcat container can directly access the index.html under WEB-INF.

Feel free to add if I am missing something.

1

There are 1 answers

3
Vy Do On

It is impossible.

Servlet 3.1 specification

Most of the WEB-INF node is not part of the public document tree of the application. Except for static resources and JSPs packaged in the METAINF/resources of a JAR file that resides in the WEB-INF/lib directory, no other files contained in the WEB-INF directory may be served directly to a client by the container.

Best practice is put your file index.html inside src/main/webapp.

Reference

http://download.oracle.com/otn-pub/jcp/servlet-3_1-fr-eval-spec/servlet-3_1-final.pdf (page 10-105)

https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html