I think you're experiencing a standard Java class loader problem.
Java treats classes loaded into different classloaders as different
classes, even though they share the same full. qual. name.
Your recompiled servlets are reloaded by a brand new class loader
to make sure the old classes are garbage collected. What you get
from the context is actuially an instance of a class loaded into
a different classloader, and (StatesBean) part in your statement
causes StatesBean to be loaded again by this new classloader that
reloaded your servlet, so
VM complains that you cannot cast objects since it thinks they
are instances of 2 completely different classes. No matter where
you place your files you'll have the same problem.

You can avoid this problem by writing some extra code and have your
bean to implement some interface.... Extra work, just restart
Tomcat every time...

Regards,
VG.

Andrey Myatlyuk wrote:
> 
> Hello Tomcat users,
> 
> I'm in a trouble. I share some object(StatesBean) between servlets. And when I
> recompile _servlet_, I got ClassCastException about shared object.
> 
> _statesBean=
>     (StatesBean)getServletContext().getAttribute(StatesBean.STATES_BEAN_NAME);
> 
> 
> Classfile for this object is placed in the same directory, where
> servlets do - web-inf/classes. Where I need to place classfile for
> this object to prevent Tomcat exceptions?
> 
> Of course, if I reload Tomcat everything is OK.
> 
> Thank you in advance!
> 
> --
> Best regards,
>  Andrey                            mailto:[EMAIL PROTECTED]
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, email: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to