if servlet1 is the servlet that puts the object into the vector and servlet2
is the servlet that tries to read them.
then these servlet may be loaded with different class loaders, which might
indicate that each one of these servlets have loaded the class CHyperLink
with different class loaders, hence you get a ClassCastException.

the only way to solve this is if the class CHyperLink loaded with the same
class loader.

one option is to:
remove the class from any WEB-INF/lib or WEB-INF/classes location (hide them
from the adaptive class loader)
add the class into a separate directory and set your system classpath to
include that location.
the CHyperLink class will now be loaded using the System class loader when
both servlets try to access it

hope this helps
Filip

~
Namaste - I bow to the divine in you
~
Filip Hanik
Software Architect
[EMAIL PROTECTED]
www.filip.net
-----Original Message-----
From: Ivan [mailto:[EMAIL PROTECTED]]
Sent: Friday, April 27, 2001 2:14 PM
To: [EMAIL PROTECTED]
Subject: Objects in Vector are loosing type


Does anyone know what is going on with the this weird problem?

I have a class named CHyperklink

I putting a vector into a session object and then adding CHyperlink objects
to the vector.

When I retrieve the vector (with no problem) from the session object, I can
cast the objects back to CHyperlinks if do it in the same servlet that put
the objects in the vector.

If i retrieve the objects from the vector from a diffrent servlet than the
one the put the objects into the vector, they all come out of the vector but
they are not instanceof CHyperlink anymore and I cannot cast them back to
CHyperlink.

When i call tostring() on the objects in the vector i get output indicating
that they are still CHyperlinks.

I am stuck because i cant cast back to the CHyperlink and call the
appropriate methods.  Does anyone know what is happending?


Here is output for tostring calls on objects in vector

novick.urlprog.CHyperlink@f11e4598
novick.urlprog.CHyperlink@97064598
novick.urlprog.CHyperlink@942a4598
novick.urlprog.CHyperlink@909e4598
novick.urlprog.CHyperlink@9c5a4598

Here is code for inserting vector

           CHyperlink hlink;
            hlink = new CHyperlink(address, description, name);
            // create hyperlink object

            HttpSession session = request.getSession();
            // get session

            Vector urls = (Vector) session.getAttribute("vector");
            // get vector from session

            if (urls == null)
            // vector does not exist yet
            {
                  urls = new Vector();
                  // create new vector

                  session.setAttribute("vector",urls);
                  // adds urls vector to session if not already there
            }

            urls.add(hlink);
            // add the hyperlink to the vector

here is code for retrieving vector

            HttpSession session = request.getSession();

            Vector v2 = (Vector) session.getAttribute("vector");
            // get vector from session

            Object obj;
            CHyperlink link;
            // temp variables

             if ( v2 != null)
             {
                   out.print("Got the vector");

                   for (int i = 0 ; i < v2.size() ; ++i)
                   {
                        obj = v2.get(i);

                        if (obj instanceof novick.urlprog.CHyperlink)
                        {
                              link = (CHyperlink) obj;
                              out.print("<br> " + link.GetHTML());
                        }

                        else
                        {
                              out.print("<br> " + obj.toString() );
                        }
               }
  }


Reply via email to