tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Helena Hjertén <>
Subject RE: It worked - Can someone explain why?
Date Thu, 30 Aug 2001 09:50:11 GMT
Hi Charles, 
All classfiles are placed in a directory structure that matches the package
name. For example: A class called JavaClass.class in a package called
"com.anything.project" must be placed in a directory structure
com/anything/project under a directory that is loaded by the class loader
(in tomcat case for example WEB-INF/classes). This goes for both servlets
and regular class files. 

When you do import "com.anything.project.JavaClass" in a normal java file,
this file must be available under a directory that matches this package
name, as well as when you call a servlet, you must call it with the package
name as in
et and the file JavaServlet.class must be available in the directory
mentioned above.

You can also put all your files into a java archive (jar-file) and place the
jar-file under WEB-INF/lib, but evenso, if you open a jarfile and check it
out (use for example winzip) you can see that there is a directory structure
that matches the package names.

-----Original Message-----
From: Charles Webber []
Sent: Thursday, August 30, 2001 03:36
Subject: It worked - Can someone explain why?

I am working through a book on servlets and JSPs.  JSPs and beans are pretty
easy, and I understand how things fit together  - still want to work on some
JDBC stuff, but that's later.
In the meantime, I wrote a servlet as part of a package called coreservlets.
I finally went through the examples that came with Tomcat and noticed in the
source that it didn't use packages and figured out both how to invoke my
servlets and where to place the class file so that it would work.  The
question is why it works this way - what is going on under the covers?
I placed my servlet class file in a directory like
$TOMCAT_HOME/webapps/examples/WEB-INF/classes/coreservlets/name.class.  On
the URL in my browser, I typed in the following:
http://host/examples/servlet/ - and it worked!!!
So the confusion I have is due to the fact that the directory path names
don't match where the servlet is located.  Can anyone explain this?  I'm
sure this is pretty straightforward - and if some document points this
ut  - if you could point me to that I'll take it from there.

View raw message