wood burning stoves 2.0*
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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlets interacting with other classes" Watch "servlets interacting with other classes" New topic
Author

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:
WEB-INF/lib/com/siteName/dbAccess/DBManager.class
WEB-INF/lib/com/siteName/dbAccess/ConnectionPool.class
and the DBTest servlet is in this path:
WEB-INF/classes/DBTest.class
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
Bill
[This message has been edited by bill bozeman (edited April 20, 2001).]
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Bill,
Move your utility classes from ...WEB-INF/lib dir to .../WEB-INF/classes dir like this.
WEB-INF/lib/com/siteName/dbAccess/DBManager.class
WEB-INF/lib/com/siteName/dbAccess/ConnectionPool.class
should be moved to
WEB-INF/classes/com/siteName/dbAccess/DBManager.class
WEB-INF/classes/com/siteName/dbAccess/ConnectionPool.class
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.
regds
maha anna
[This message has been edited by maha anna (edited April 20, 2001).]
Frank Carver
Sheriff

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 frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: servlets interacting with other classes