http://hostname:port/WebAppName/Here, the context root of the server is hostname, and the context path of the web applicaton is WebAppName.However, in practice we may want to use only the server's host name to access the web application, via this kind of URL:
http://hostname:port/In this case the context path of the web application is united with the server root - it would be very convenient for many cases. So, how to setup Tomcat server to change the default?The simplest way is to deploy your Java web application as ROOT.war under the webapps directory. Follow these steps:- Rename your web application's WAR file to ROOT.war
- Rename or delete the default ROOT directory.- Copy your ROOT.war file to webapps directory.- Start Tomcat, and you will see it extracts your ROOT.war file to deploy your web application.- Now your web application can be accessed via server hostname (or its context root). Enjoy!
Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.