You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jason Reilly <ja...@pajato.com> on 2002/09/13 06:01:25 UTC

ClassCastException error

Let's say I have a Vector of objects.  I put that Vector into the
session in my Action.perform() method.  I then do a generic forward to
a jsp.  Nothing fancy here.... But, when I try to access that Vector
in a jsp, I am getting a ClassCastException on the objects in the
Vector.  When I do a getClass().getName() on any of the objects in the
Vector, it returns the exact object that I originally put in the
Vector.  So I am assuming that it is a ClassLoader issue.  I was told
to rearrange the jars in my classpath, but that did not resolve
anything.  Does anyone have any insight into how I might resolve this?

jdr

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: ClassCastException error

Posted by Jason Reilly <ja...@pajato.com>.
Eddie Bush <ek...@swbell.net> writes:

 > You mean you had set CLASSPATH to include struts.jar?  I don't think 
 > Tomcat pays attention to CLASSPATH.  You're guaranteed that your classes 
 > folder will be in the CLASSPATH provided to your application though -- 
 > and everything in lib will be mounted up too.

I edited <TOMCAT_HOME>/bin/catalina.sh to have struts.jar in the
classpath.  

jdr





--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: ClassCastException error

Posted by Eddie Bush <ek...@swbell.net>.
Jason Reilly wrote:

>"Michael Lee" <ml...@hotmail.com> writes:
>
> > Need more info.
> > What app server?
>
>Tomcat 4.0.4 
>Struts 1.0.2
>
> > What jdk?
>
>j2se1.3
>
>Thanks...but, I figured out what was wrong.  I had struts.jar in the
>classpath, but not in /WEB-INF/lib/.  I am a bit of a newbie, so I am
>still unsure why putting struts.jar in /WEB-INF/lib/ resolved my
>ClassCastException issue.  Go figure....
>
You mean you had set CLASSPATH to include struts.jar?  I don't think 
Tomcat pays attention to CLASSPATH.  You're guaranteed that your classes 
folder will be in the CLASSPATH provided to your application though -- 
and everything in lib will be mounted up too.

Putting the JAR with your app is a recommended solution because you can 
then, say, migrate one app at a time to the newer versions as they 
become available.

Regards,

Eddie



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: ClassCastException error

Posted by Michael Lee <ml...@hotmail.com>.
I was going to suggest that but I usually see NoClassDefFoundException. I
wasn't sure about your deployment environment so I didn't suggest this. The
ClassCastExcpetion occurred because of this reason (LEARN THIS!! VERY
IMPORTANT TO J2EE DEVELOPMENT);
One class loader can load another. The child can see the parent's classes
but not vice versa.
Here's the way weblogic works (not sure about the ?? loader), I'm sure
tomcat is about the same.

Weblogic class loader loads -> ?APP class loader loads? -> EJB class loader
loads -> WAR class loader

This means EJBs can use classes in the weblogic system but they can not call
ejbs, etc. The reason they did this is so you can call an EJB from a WAR
without class casting problems (anyone that has ever used 5.1 before sp4
knows about this). If you put struts in the system class loader then when it
tries to access classes in the WAR class loader they are different/or dont
exist then the classes it has. Hence,
ClassCastException/NoClassDefFoundException etc. I have also seen security
violation type exceptions on these also.
Hope this helps,
Mike


----- Original Message -----
From: "Jason Reilly" <ja...@pajato.com>
To: <st...@jakarta.apache.org>
Sent: Friday, September 13, 2002 11:30 AM
Subject: Re: ClassCastException error


> "Michael Lee" <ml...@hotmail.com> writes:
>
>  > Need more info.
>  > What app server?
>
> Tomcat 4.0.4
> Struts 1.0.2
>
>  > What jdk?
>
> j2se1.3
>
> Thanks...but, I figured out what was wrong.  I had struts.jar in the
> classpath, but not in /WEB-INF/lib/.  I am a bit of a newbie, so I am
> still unsure why putting struts.jar in /WEB-INF/lib/ resolved my
> ClassCastException issue.  Go figure....
>
> jdr
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: ClassCastException error

Posted by Jason Reilly <ja...@pajato.com>.
"Michael Lee" <ml...@hotmail.com> writes:

 > Need more info.
 > What app server?

Tomcat 4.0.4 
Struts 1.0.2

 > What jdk?

j2se1.3

Thanks...but, I figured out what was wrong.  I had struts.jar in the
classpath, but not in /WEB-INF/lib/.  I am a bit of a newbie, so I am
still unsure why putting struts.jar in /WEB-INF/lib/ resolved my
ClassCastException issue.  Go figure....

jdr


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: ClassCastException error

Posted by Michael Lee <ml...@hotmail.com>.
Need more info.
What app server?
What jdk?
Stack trace?
Offensive code?
Mike

----- Original Message -----
From: "Jason Reilly" <ja...@pajato.com>
To: <st...@jakarta.apache.org>
Sent: Friday, September 13, 2002 12:01 AM
Subject: ClassCastException error


>
> Let's say I have a Vector of objects.  I put that Vector into the
> session in my Action.perform() method.  I then do a generic forward to
> a jsp.  Nothing fancy here.... But, when I try to access that Vector
> in a jsp, I am getting a ClassCastException on the objects in the
> Vector.  When I do a getClass().getName() on any of the objects in the
> Vector, it returns the exact object that I originally put in the
> Vector.  So I am assuming that it is a ClassLoader issue.  I was told
> to rearrange the jars in my classpath, but that did not resolve
> anything.  Does anyone have any insight into how I might resolve this?
>
> jdr
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>