tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrés Glez. <>
Subject Re: ClassCastException while sharing objects accross applications
Date Tue, 04 Oct 2005 08:43:37 GMT
What about using JNDI to share objects between webapps?

I think that:

String context = "java:comp/env/xxxx";
InitialContext ic = new InitialContext();
ClassX c = (ClassX) ic.lookup(sContexto);
should return the same object to different servlets/webapps, if you define 
the jndi-resource globally, i.e., in conf/server.xml

----- Original Message ----- 
From: "Seva Popov" <>
To: "Tomcat Users List Surya Mishra" 
<"tomcat-user@jakarta.apache.orgsurya.mishra">; "Tomcat Users 
List" <>
Sent: Tuesday, October 04, 2005 8:41 AM
Subject: RE: ClassCastException while sharing objects accross applications

The type in Java is a combination of a fully qualified class name and its 
defining classloader. So the two objects with the same class name are 
considered different types in your two web applications because each web 
application is loaded by the dedicated webapp classloader.

To solve your problem you can use object serialization or if your objects 
are the java beans you can use the java.beans encoding.

"The XMLEncoder class is a complementary alternative to the 
ObjectOutputStream and can used to generate a textual representation of a 
JavaBean in the same way that the ObjectOutputStream can be used to create 
binary representation of Serializable objects. "



From: Surya Mishra []
Sent: Mon 10/3/2005 4:12 PM
To: Tomcat Users List
Subject: ClassCastException while sharing objects accross applications


I am trying to share an object between 2 applications deployed on the same
tomcat server. I have put the object in the ServletContext in my first
application. I access the object using
The object comes in fine but it won't let me cast it to the actual Object
Type. I get a ClassCastException. I tried printing the name of the class.
That also came fine (same class name).

Thanks in advance.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message