Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Servlets w/ other classes

Status
Not open for further replies.

flawless69

Programmer
May 31, 2002
86
US
Greetings all,

I have a servlet class(Servlet1) which contains an instance of another non-servlet class(Class1) that contains instances of several other classes and contains a vector instance. Using a main method class that simulates the method call Servlet1 makes to Class1, I can get the desired return values and all works great.
However when the servlet is invoked, It appears that Class1 and all the classes it talks to, are not working. The vector that is returned by Class1 ends up being empty when invoked by Servlet1 (as opposed to containing several objects when main method calls it).
Is there any reason that the servlet wouldn't perform EXACTLY the same as any other class when calling and containing instances of other classes?

A bit confusing, I know....
Thanks ahead,

Derek --Derek

"Fear not the storm for this is where we grow strong."
 
Hi flawless69:

If your servlet can see your classes I can't figure what can be wrong.

anyway, check the content of the parameters that the servlet send to the class against the parameters that the test main send to the class. (System.out.println - out.println). It could be different. has happened...

If it doesn't work, post a bit of your code and specify your servlet engine.

Hope it helps. Pedro Andrés Solorzano
Pontificia Universidad Javeriana
Bogotá, Colombia, SurAmérica.
 
Well thing is, I think the Java is ok because it throws an exception after it gets into the instance of Class1 and gets to the point where the Vector that Class1 contains, is accessed. In this case, the first object contained in the Vector is not there. Class1 gets this vector from a method call to another class. This class comingfrom another class is empty.
I am thinking that this is more of an issue with Tomcat or something with the way servlets communicate with non-servlet classes. I have the servlet class in the same package as the rest of the classes and per Tomcat's instructions, they are all in the servlets folder (i.e. they are all members of the servlets package).
Is there something in Tomcat that specifies that non-servlet classes cannot be in this folder?
I also wonder if variables must be declared differently in classes that are to be used in Web applications.

Any ideas? --Derek

"Fear not the storm for this is where we grow strong."
 
Ok here's some more info....
I decided to try something more simple. I created a regular class that contains an instance of the Vector class. I then had the servlet create an instance of the regular class and called a method that would return the Vector. The servlet then contained a vector instance that I set to the returning vector from the other class.
Turned out that the Vector returned from the other class threw a nullobject exception when accessed in the servlet.
Is there something that must be done in Tomcat to deal with other classes? Like I know about declaring servlets in the web.xml file but do other classes need to be declared somewhere as well?
Any insight is appreciated.

--Derek

"Fear not the storm for this is where we grow strong."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top