hi all, when we use setAttribute() on any object (request,session etc) how does it (the attribute we set) get stored? does it get serialized or not? (or does it need to be Serializable or not to be precise?). i doubt, it need not be serializable but i'm not sure. please clarify my doubt. regards maulin
It should implement Serializable. You may run into problems later if you don't...
Tony Alicea Senior Java Web Application Developer, SCPJ2, SCWCD
Joined: Jan 30, 2000
I forgot: The attrib gets set as in a hash table: A dictionary. Name/value pair. Notice that the object gets stored as an Object so you may have to cast when you get it back.
Joined: Nov 04, 2001
hi tony, thanks for the reply. i asked the question to get cleared about one the of concept. it is related to MY reply for the one of the post at here as u can see the problem of having ClassCastException, i assumed that similar thing will happen if i write an object to the applet from the servlet and access it using readObject() in the applet and then cast it back to the original type. means, it should raise ClassCastException if the class loaders for the applet and the servlet are different (which are different i guess. i have to yet make sure). what i have is, - applet having class "TestClass" in the applet code itself (its not an innerclass though, its two classes declare in one .java file). - this applet connects to the servlet using URLCOnnection - the servlet has the same class "TestClass" in the Servlet code (two classes declared in one .java file) - the servlet returns an object of "TestClass" to the applet - the applet gets back that object and re-cast it to the "TestClass" object Here, i DON'T get ClassCastException when i re-cast TestClass object in the applet. why? if the two classloaders (for the applet & the servlet to which i connect) are different and both of them have different copies of the "TestClass.class" then why it doesn't give me ClassCastException? the last post from me for the same thread i gave link above is not correct though (saying - there is a problem with the webserver). i agree that if the object isn't serializable then setAttribute() might not work properly... hope u understand my question. i have been thinking of the reason for sometime but i am not able to figure out why i'm not getting ClassCastException in the applet....thats why i was plunging myself on serialization fundamentals in setting attributes etc and wanted to make sure what is happening actually... regards maulin