Are any of the classes you are using defined outside of the web app.  That
is, are you using any libraries, or class files which you specify on the
classpath prior to tomcat starting, which may also be in your web-app.  It
is situations like this which the more experienced folks point to as the
cause to this problem.  Generally, the type of error you are mentioning
happen if the class is loaded by a higher level class loader than the
JSP/Servlet's loader, but the JSP/Servlet sees the web-app's WEB-INF class
and libs before the system's classes and libs.  So if the object was created
by the system class loader (with it's copy of the class), it has a different
'Class ID' than one loaded by the JSP/Servlet class loader.

In short, try to remove all elements from your class path and extentions
directories, and put them all in the webapp for a short testing period. See
if this exposes solves the error or exposes a place where some code would
get a class from a different class loader than from others.  Then you can
slowly move the libraries back where they came from to better isolate your
problem.

Hope that helps,
Paul


-----Original Message-----
From: Cory L Hubert [mailto:[EMAIL PROTECTED]]
Sent: Sunday, April 29, 2001 3:33 PM
To: [EMAIL PROTECTED]
Subject: RE: Wierd Casting Problem. Tomocat Bug?


        Casting could happen in a regular fashion if you just restart.  Wierd.  Is
anyone planning on fixing this issue, no developer should have a 12 hour
problem because of a faulty Dynamic class loader.

-----Original Message-----
From: Cory L Hubert [mailto:[EMAIL PROTECTED]]
Sent: Sunday, April 29, 2001 11:29 AM
To: [EMAIL PROTECTED]
Subject: RE: Wierd Casting Problem. Tomocat Bug?


        When I restart that little trick doesn't work anymore.  I have a feeling
it's defenaitley a bug.  Can anyone confirm?

-----Original Message-----
From: Cory L Hubert [mailto:[EMAIL PROTECTED]]
Sent: Sunday, April 29, 2001 11:14 AM
To: [EMAIL PROTECTED]
Subject: RE: Wierd Casting Problem. Tomocat Bug?


        I found out the problem.  This looks like an extreme hack though.

        <$=((member) ((Object)e.nextElement()) ).getFname()%>

        Works.   But why do I have to cast to an Object before I cast it back to
it's appropiate type.   My only guess is that the Servlet DownCast the
Vector to an Object (because there is some reflection that goes on) before
setting the Attribute and passing it to JSP.
        But the actual member objects are put in the Vector as member Objects.
Any Ideas?  Does anyone thing it's wierd that you have to cast to and Object
then to the Type.
        I believe this isn't a Java Bug it may be a Tomcat Bug.  Because I don't
have to cast to an Object, if I am casting to member objects in the Servlet.


-----Original Message-----
From: Cory L Hubert [mailto:[EMAIL PROTECTED]]
Sent: Sunday, April 29, 2001 3:46 AM
To: [EMAIL PROTECTED]
Subject: Wierd Casting Problem.


        Ok.  Here is the problem.  I am using Model 2 Architecture.  So my Servlet
handles all the biz logic and pushes the results that are then displayed by
jsp pages.

                Within a jsp page I grab my vector from the request like so..

                Vector mems =(Vector)request.getAttribute("response");

                        Then I try to loop around it and cast it to the appropiate 
Object. Like
so...
                <%
                for (int i=0; i < mems.size(); i++) {

                        member m = (member)mems.get(i);
                %>
                        <%=m.getFname()%>
                <%}%>


                I get a ClassCastException.   But when I do a toString on the Object
itself without casting, it specifies the package name of the object that I
am trying to cast to.

                To make matters wierder.  When I do a getClass().isInstance(THE OBJECT 
I
WANT TO CAST TO) it returns false?

                What is going on here?  Is this some classLoader issue?


                Some tips that might help figure this issue out......

                        I am importing the class I am casting, in the JSP page. like 
so..

                        <%@page import="thepackage.member, java.util.*"%>

                        And the class itself isn't in a jar.  It's in the 
WEB-INF/classes
directory.

                        I also changed the container from a Vector to an ArrayList and 
got the
same results.

                        And I can instantiate the member object itself and use it in 
the jsp
page.

                Any ideas?  Please.  Someone, HELP!!!


Reply via email to