0

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
raikumardipak
  • 1,461
  • 2
  • 29
  • 49

1 Answers1

0

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

Vy Do
  • 46,709
  • 59
  • 215
  • 313
  • Why is it impossible? Aren't we doing the same for the jsps placed inside WEB-INF as we render them through servlet? The API says that it may not be served rather than cannot be served. Correct me if I am missing something. – raikumardipak Jun 05 '17 at 08:32
  • In the case (your reply), with JSP file, it is accessing indirectly. – Vy Do Jun 05 '17 at 08:35
  • Yes. So we can still access it indirectly but that's not a good practice. At least one file (default) should be public. – raikumardipak Jun 05 '17 at 08:56