Venkatt Guhesan has been an Enterprise Java Architect with over 15 years of software development experience living and working in the Baltimore, Maryland area. Enjoys developing in Java, Scala, Groovy, Python, Ruby, Cold Fusion and Perl. Strong supporter of open source technologies including Linux and Apache Foundation. Venkatt is a DZone MVB and is not an employee of DZone and has posted 12 posts at DZone. View Full User Profile

Understanding Tomcat Configuration

12.25.2010
| 7447 views |
  • submit to reddit
Case #1:
When the Tomcat config is this:
<Host name="localhost" appBase="C:/apps/apache-tomcat/null"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">

<Context path="/" docBase="C:/apps/apache-tomcat/DeployedApps/HelloWorld" debug="0" reloadable="false" crossContext="false"/>

Then…
http://localhost/index.jsp yields to the “index.jsp” under HelloWorld folder.
http://localhost/HelloWorld/index.jsp yields to a “404 Page”.

Case #2:
When the Tomcat setup is this:

<Host name="localhost" appBase="C:/apps/apache-tomcat/null"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">

<Context path="/hw" docBase="C:/apps/apache-tomcat/DeployedApps/HelloWorld" debug="0" reloadable="false" crossContext="false"/>

Then…
http://localhost/index.jsp yields to a “blank page”.
http://localhost/HelloWorld/index.jsp yields to a “blank page”.
http://localhost/hw/index.jsp yields to the “index.jsp”.

So if the objective is to deliver “HelloWorld” as the default application for the root context, then the configuration for that instance should like “case #1”. If the objective of a particular application to be bound to a “path”=”application context”, then we need to deploy that instance as “case #2”.

I hope this clarifies the two models.

References
Published at DZone with permission of Venkatt Guhesan, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Hani Nadra replied on Sun, 2010/12/26 - 6:00pm

Hani Nadra replied on Sun, 2010/12/26 - 5:59pm

In the first case, you should use path="" to indicate a default application (see documentation from tomcat and JEE). This will ensure that request.getServletContext() returns an empty string.

Yes, if you use path="/", the request to http://localhost/index.jsp will go to index.jsp, but you will run into funny things with libraries that use request.getContextPath() (things like c:url and spring tags) and end up with URLs like //index.jsp (with the two slashes).

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.