Laiwu Luo wrote:

> I am trying to get familiar with Tomcat 3.1 environment. My simple
> question is:
>
> Without creating a new web application, where I should put my servlet
> files? I thought I could use the default "examples" application. So I
> did copy Counter.java and Counter.java into "examples/servlets"
> directory. But using the following URLs to access the servlet page
> always got "Error 404".
>
> http://localhost:8080/examples/servlets/Counter
> http://localhost:8080/examples/servlet/Counter
>
> Could anyone help to me to figure out in which directory I should copy
> my servlet file?
>

Put the class files for your servlets (and any other classes that they
reference) into the WEB-INF/classes subdirectory for the web application you
want to use.  Then, you can reference them with:

    http://localhost:8080/examples/servlet/Counter

(or modify the web.xml file to map a different name to your servlet).

The URI you use to request a servlet has nothing to do with where the
corresponding class file lives -- it is up to the container to translate the
URI to the corresponding servlet.  In this particular case, what happens is
that there is a built-it servlet that receives all requests that begin with
"/servlet" (relative to the context path of your app).  This servlet, called
the "invoker" servlet, looks at the rest of the URI and assumes it is the class
name of a Java class -- which it then loads and executes as a servlet.  Classes
(servlet or not) are loaded from the WEB-INF/classes subdirectory, or from a
JAR file under WEB-INF/lib, within your web application.

Look in the file $TOMCAT_HOME/conf/web.xml to see the default setup for all web
applications in Tomcat -- you will find a <servlet> entry for the invoker
servlet there, plus a <servlet-mapping> entry that connects "/servlet/*" to the
invoker servlet.

>
> Thanks,
>
> --
> Laiwu Luo
>

Craig McClanahan

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to