File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Tomcat Servlet path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Tomcat Servlet path" Watch "Tomcat Servlet path" New topic

Tomcat Servlet path

Nair Anoop
Ranch Hand

Joined: May 09, 2001
Posts: 68
I have installed Tomcat on a Win NT machine. Its working correctly. But I am little confused about the concept of "Contexts". One of the pre-defined contexts is :
"/examples" => "/webapps/examples/"
There is a file index.html in "/webapps/examples/servlets" which calls the example servlets as http://localhost:8080/example/servlet/helloworld
But there is no directory called "servlet" in the examples directory. Instead all class files are in "web-inf/classes"
How does Tomcat know that "web-inf/classes" => "servlet/" ??
Thanks in advance,
Marcos Maia
Ranch Hand

Joined: Jan 06, 2001
Posts: 977
Hi, I�m not working with tomcat but usually this path web-inf/classes is mapped to servlet at some xml configuration file.
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

This come with the ( ?)
Servlet Specification.
Any app server confirming to the Specs from Sun will do this
From Servlet Specs 2.2, Section 9.4

A special directory exists within the application hierarchy named �WEB-INF�. This directory
contains all things related to the application that aren�t in the document root of the application. It is
important to note that the WEB-INF node is not part of the public document tree of the application.
No file contained in the WEB-INF directory may be served directly to a client.
The contents of the WEB-INF directory are:
� /WEB-INF/web.xml deployment descriptor
� /WEB-INF/classes/* directory for servlet and utility classes. The classes in this directory
are used by the application class loader to load classes from.
� /WEB-INF/lib/*.jar area for Java ARchive files which contain servlets, beans, and other
utility classes useful to the web application. All such archive files are used by the web
application class loader to load classes from.

- satya

Take a Minute, Donate an Hour, Change a Life
Nair Anoop
Ranch Hand

Joined: May 09, 2001
Posts: 68
Thanks a lot for your helpful response.
Nair Anoop
Ranch Hand

Joined: May 09, 2001
Posts: 68
I am still unclear about one thing:
How does Web-Inf/classes map to "examples/servlet" ?
Is this specified in some XML descriptor file ?
[This message has been edited by Nair Anoop (edited August 01, 2001).]
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

Tomcat is the same as most other web servers in that it allows you to build up a web site that contains "virtual directories". For example: "". In your webserver configuration (server.xml in tomcat's case), you map the virtual directory (web alias) to a real file directory using a context. So, for example, you can make requests against the "herbalviagra" directory come from "F:\GetRichQuick\scamoftheweek" by defining the context:
<context path="/herbalviagra" docBase="f:/GetRichQuick/scamoftheweek"/>
The most common context, is of course, the root one, so that would be context path "/". By default, that's mapped into the TOMCAT_ROOT/webapps directory.
Within the REAL directory (f:/GetRichQuick/scanoftheweek or TOMCAT_ROOT/webapps) you unpack your WAR to provide the WEB-INF/classes and other subdirectories as needed.
A complex setup may involve multiple contexts, some of which may be located in different virtual hosts. All of this is set up in server.xml.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: Tomcat Servlet path
It's not a secret anymore!