• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

question about setAttribute()

 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It should implement Serializable.
You may run into problems later if you don't...
 
Tony Alicea
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
If you send is by car it's a shipment, but if by ship it's cargo. This tiny ad told me:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic