tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kitching Simon <Simon.Kitch...@orange.ch>
Subject RE: Servlet Directory
Date Tue, 24 Oct 2000 12:17:40 GMT
Hi,

Just to spell things out a bit clearer:

The code for a servlet class, and any non-library
classes it uses, must be in the classpath. Your
best options are:
(a) put them under {yourwebapp}/WEB-INF/classes,
in a subdirectory that matches your package structure.
(b) put them in a jar file, in {yourwebapp}/WEB-INF/lib

In either case above, tomcat automatically adds the
directories/libs to its classpath when it starts.

You *can* put your servlet classes elsewhere on your 
disk, and make sure your CLASSPATH points to them 
before starting tomcat, but there are many disadvantages 
to this,  including making it difficult to install your code 
elsewhere, and not being able to use the servlet 
auto-reload feature.

Now that your class is *loadable* by tomcat, you need
to tell tomcat what URLs map to what servlets. 

There is an entry in $TOMCAT_HOME/conf/web.xml which
sets up a default mapping for servlets; for any url of form
/webapp/servlet/servletname, an attempt is made to
do a "loadClassForName(servletname)" and if
successful, the request is passed off to the found class.
Of course, the class to be loaded merely has to be in
the classpath somewhere (see (a) and (b) above).
[[NB: this only applies in tomcat3.1; I hear that tomcat3.2
does not have a $TOMCAT_HOME/conf/web.xml file,
in which case I'm not sure how or if the default servlet
mapping gets set up...]]

If you don't like this default mapping, you just define
your own (url->servletclass) mappings in the file
yourwepapp/WEB-INF/web.xml. See the file
$TOMCAT_HOME/conf/web.dtd to see what tags
are allowed in the web.xml file; then read the sun
servlet specs. NB: don't modify the web.xml file
in TOMCAT_HOME/conf, create your own inside
your webapp/WEB-INF.

Note that the servlet class *never* lives *at* the
url that the user enters; the url is always looked up
to find a corresponding class name, and then the
servlet class is loaded from the classpath.

I hope this clarifies things a bit...

Regards,

Simon
> -----Original Message-----
> From:	Clark D. Richey, JR. [SMTP:cdrichey@bellatlantic.net]
> Sent:	Tuesday, October 24, 2000 3:22 AM
> To:	tomcat-user@jakarta.apache.org
> Subject:	RE: Servlet Directory
> 
> The class file has to be in Tomcat's classpath. Where are you putting the
> servlet's class file?
> 
> > -----Original Message-----
> > From: Corey A. Johnson [mailto:cjohnson@cniweb.net]
> > Sent: Monday, October 23, 2000 8:15 PM
> > To: tomcat-user@jakarta.apache.org
> > Subject: Servlet Directory
> >
> >
> > Hello all,
> >
> > First, let me apologize... this is so simple... but i have been beating
> > my head against the wall for almost 20 hours straight now...
> >
> > I have successfully installed Tomcat on my Solaris... With Apache 1.3.14
> >
> > Everything seems to be working fine... JSPs work well... looking through
> > the logs... no errors...  but i can not get any servlets to work in my
> > defined servlet directory.  I must be missing something very simple.
> > When i try to invoke a servlet, the tomcat.log file shows:
> >
> > Context log: path="" Class Not Found in init
> >  java.lang.ClassNotFoundException: testAllego
> >
> >
> > In my tomcat.conf file.. i have the line:
> >
> > ApJServMount /servlet /root
> >
> > And i have this in my server.xml file:
> >
> > <Context path="" docBase="/export/home/cni/servlet" debug="0"
> > reloadable="true" >
> > </Context>
> >
> >
> > I feel like i am so close... because ay least it is "trying" to load the
> > servlet class... but tomcat can't find it..
> >
> > please help... i need some sleep...
> >
> > thanks in advance.
> >
> > Cj
> > --
> > Corey A. Johnson
> > Creative Network Innovations, Inc.
> > 1-800-264-5547 ** 1-321-259-1984
> >

Mime
View raw message