Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@www.apache.org Received: (qmail 35752 invoked from network); 4 Oct 2005 06:41:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 4 Oct 2005 06:41:50 -0000 Received: (qmail 58510 invoked by uid 500); 4 Oct 2005 06:41:35 -0000 Delivered-To: apmail-jakarta-tomcat-user-archive@jakarta.apache.org Received: (qmail 58377 invoked by uid 500); 4 Oct 2005 06:41:35 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Tomcat Users List" Reply-To: "Tomcat Users List" Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 58366 invoked by uid 99); 4 Oct 2005 06:41:34 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Oct 2005 23:41:34 -0700 X-ASF-Spam-Status: No, hits=0.9 required=10.0 tests=HTML_40_50,HTML_MESSAGE,SPF_SOFTFAIL X-Spam-Check-By: apache.org Received-SPF: softfail (asf.osuosl.org: transitioning domain of seva_popov@tvworks.com does not designate 168.75.97.99 as permitted sender) Received: from [168.75.97.99] (HELO relay.metatv.com) (168.75.97.99) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Oct 2005 23:41:38 -0700 Received: from [192.168.1.133] (HELO mailserver.metatv-ds.metatv.com) by relay.metatv.com (CommuniGate Pro SMTP 4.0.6) with ESMTP id 10637637 for tomcat-user@jakarta.apache.org; Mon, 03 Oct 2005 23:41:11 -0700 X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C5C8AE.9BE4B6F0" Subject: RE: ClassCastException while sharing objects accross applications Date: Mon, 3 Oct 2005 23:41:11 -0700 Message-ID: <83E753BE7B6A324ABB336245BAF1DAAC02305A1C@mailserver.metatv-ds.metatv.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: ClassCastException while sharing objects accross applications Thread-Index: AcXIcAbU/vFaAuZiTgi46gB/P9tssgAPOTiA From: "Seva Popov" To: "Tomcat Users List Surya Mishra" <"tomcat-user@jakarta.apache.orgsurya.mishra"@gmail.com>, "Tomcat Users List" X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N ------_=_NextPart_001_01C5C8AE.9BE4B6F0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable 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. =20 To solve your problem you can use object serialization or if your = objects are the java beans you can use the java.beans encoding. =20 "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. " =20 =20 --Seva ________________________________ From: Surya Mishra [mailto:surya.mishra@gmail.com] Sent: Mon 10/3/2005 4:12 PM To: Tomcat Users List Subject: ClassCastException while sharing objects accross applications Hi, 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 ServletContext.getContext("firstApp").getAttribute("object");. 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. -Surya ------_=_NextPart_001_01C5C8AE.9BE4B6F0--