This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Servlets and the fly likes servlets interacting with other classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlets interacting with other classes" Watch "servlets interacting with other classes" New topic

servlets interacting with other classes

bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
I tried to do some research on this, but I haven't found the answer yet.
I have 3 class files. 1 is a servlet and the other 2 are utility files that I created. The utility files are in a package, say it is named "com.siteName.dbAccess" and the two utility files are named "DBManager" and "ConnectionPool".
What I want is to have the servlet, say this is named "DBTest" to call the ConnectionPool class, which in turn uses the DBManager class. I have my classpath correct on my local machine, so I can compile it and run a non-servlet to test the two utility files, so I know they work, but I haven't been able to get it to work as a servlet.
I did edit my web.xml (My host is using Tomcat) and created an alias to the DBTest servlet. The two utility files are in a path like this:
and the DBTest servlet is in this path:
So, with all that said, I get a ClassNotFound error for the class ConnectionPool when I run the servlet. Is there something else in the web.xml that I need to set up so that the class DBTest can see these utility classes? Actually I will want many of my servlets to see these classes, so is there something I need to set up so that all of my servlets can see these classes?
I am stumped
[This message has been edited by bill bozeman (edited April 20, 2001).]
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Move your utility classes from ...WEB-INF/lib dir to .../WEB-INF/classes dir like this.
should be moved to
In all your servlets source files which make use of this package, put import statements like this.
import com.oreilly.servlet.*; //an example
Give it a try!
The lib dir is meant for ****.jar files. All utility classes go under WEB-INF/classes dir.
maha anna
[This message has been edited by maha anna (edited April 20, 2001).]
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
Alternatively, if you really want to put your classes in the "lib" directory, you can always put them into a jar first.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
I agree. Here's the link:
subject: servlets interacting with other classes
It's not a secret anymore!