Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

and Google and Yahoo are your friends.

How do I make my web application be the Tomcat default application ?

Congratulations. You have created and tested a first web application (traditionally called "mywebapp"), users can access it via the URL "http://myhost.company.com/mywebapp". You are very proud and satisfied.
But now, how do you change the setup, so that "mywebapp" gets called when the user enters the URL "http://myhost.company.com" ?

Wiki Markup
The pages and code of your "mywebapp" application currently reside in (CATALINA_BASE)/webapps/mywebapp/. In a standard Tomcat installation, you will notice that under the same directory (CATALINA_BASE)/webapps/, there is a directory called ROOT (the capitals are important, even under Windows).  That is the residence of the _current_ Tomcat default application, the one that is called right now when a user calls up "http://myhost.company.com\[:port\]". The trick is to put your application in it's place.

First stop Tomcat.BR Then before you replace the current default application, it may be a good idea to make a copy of it somewhere else.BR Then delete everything under the ROOT directory, and move everything that was previously under the (CATALINA_BASE)/webapps/mywebapp/ directory, toward this (CATALINA_BASE)/webapps/ROOT directory. In other words, what was previously .../mywebapp/WEB-INF should now be .../ROOT/WEB-INF (and not .../ROOT/mywebapp/WEB-INF).

Just by doing this, you have already made you webapp into the Tomcat default webapp.

One step is left : you also need to have, within your application, a default servlet. This, you do by means of an appropriate url-mapping in the WEB-INF/web.xml configuration file of your application. Make sure you have something like this in that file :

No Format

   <servlet>
        <servlet-name>My First Servlet</servlet-name>
        <servlet-class>my.Servlet.Number1</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>My First Servlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

Restart Tomcat and you're done.BR Call up "http://myhost.company.com/" and enjoy.

Wiki Markup
For more information about this, consult this page : 
\[http://tomcat.apache.org/tomcat-6.0-doc/config/context.html The Context Container\]