> I have added an object to the session using setAttribute from
> within a servlet then later from within a jsp page I try to pull the
object out of
> the session using session.getAttribute.  My line of code looks like:

> TestObject to = (TestObject)session.getAttribute("MyObject");
>
> but I keep getting a ClassCastException.  What am I doing wrong?

It looks like the object reference that you put in the session is not
assignment
compatible to type TestObject. That is why you are getting
ClassCastException.

You can cast the object reference binded in the session to TestObject type
if and only if

1. The object reference is instance of TestObject Class OR
2. The object reference has TestObject as its super class OR
3. TestObject is an interface and the class of the object in the session
either
   directly or indirectly implements the TestObject interface.

So check the class of the instance that ur binding and see if it is
assignment compatible to TestObject type.

Hope it helps...

-Shiraz

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to