tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ernesto Garcia" <Egar...@genesyslab.co.uk>
Subject Inner class session attributes not supported?
Date Thu, 03 Nov 2005 14:59:30 GMT
I define a static inner class inside my JSP, I create an instance of it and then I keep the
resulting object as a session attribute. When getting the attribute again I will get a ClassCastException
when downcasting to my inner class. Is this a bug or standard behaviour?

Thanks,
Ernesto GarcĂ­a
 
<html>
  <%!
  private static class MyInnerClass {
    private int number;
    public MyInnerClass(int number) { this.number = number; }
    public void increment() { this.number++; }
    public String toString() { return Integer.toString(number); }
  }
  %>
 
  <%
  Object instanceObj = session.getAttribute("instance");
  if (instanceObj == null)
    session.setAttribute("instance", new MyInnerClass(1000));
  else {    
    // Uncomment the following line to get ClassCastException:
    //MyInnerClass instance = (MyInnerClass)instanceObj;
    //instance.increment();
  %>
    <p>instanceObj.getClass() = <%= instanceObj.getClass() %>
    <p>instanceObj = <%= instanceObj %>
  <%
  }
  %>
</html>
 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message