33

I am just getting started to learn about Web Apps and deploying them to Tomcat. So I started with a sample web app project - made up of struts, hibernate, etc., etc.

The ANT build was successful. Also, was able to deploy the web app through an xml under Catalina/host. I am able to open the web site with no issues.

This is the structure of my web app

-exploded

     -WEB-INF

          -classes

          -lib

          -web.xml

    -index.jsp

    -welcome.html

My question is

How does Tomcat know which is the first page / starting page / home page that it is supposed to open? Which file is this specified in?

Community
  • 1
  • 1
Van de Graff
  • 5,043
  • 13
  • 39
  • 41

2 Answers2

59

In any web application, there will be a web.xml in the WEB-INF/ folder.

If you dont have one in your web app, as it seems to be the case in your folder structure, the default Tomcat web.xml is under TOMCAT_HOME/conf/web.xml

Either way, the relevant lines of the web.xml are

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

so any file matching this pattern when found will be shown as the home page.

In Tomcat, a web.xml setting within your web app will override the default, if present.

Further Reading

How do I override the default home page loaded by Tomcat?

JoseK
  • 31,141
  • 14
  • 104
  • 131
  • Thanks Jose. I do have a web.xml in WEB-INF/ folder with tag pointing to index.jsp. Does this index.jsp refer to the one under the "exploded" folder as shown in my question above? – Van de Graff Oct 20 '10 at 10:19
  • Yes, the index.jsp is in the root within your web app i.e. the one you see under "exploded". Try combinations of renaming the JSP itself or change the web.xml to confirm how it behaves. – JoseK Oct 20 '10 at 10:29
  • May I add that depending on your Apache configuration you may also have to override DirectoryIndex in an .htaccess in the same folder as your .htaccess (assuming overrides with .htaccess are permitted at all): DirectoryIndex index.jsp Otherwise you might still get an access error. – Webel IT Australia - upvoter Aug 10 '15 at 05:24
1

I already had index.html in the WebContent folder but it was not showing up , finally i added the following piece of code in my projects web.xml and it started showing up

  <servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping> 
Nostalgic
  • 300
  • 1
  • 4
  • 18