File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes context.setAttribute (object) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "context.setAttribute (object)" Watch "context.setAttribute (object)" New topic

context.setAttribute (object)

Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 484

Hi all,
I got an question regarding context.setAttribute (object) , for instance :
here i made hashmap then put it as an attribute in the context, my question is , if i changed the "key1" after setting the hashMap in the context , is it will be reflected directly or i need to write context.setAttribute ("hashMap", temp) ; after line 4 ?

Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
You'll find the answer by printing out the contents of the hash map after the 4th line!

OCJP 6 (93%)
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13036
The reference to the HashMap now exists in two places - local variable and context, but it is still the same HashMap.

I agree. Here's the link:
subject: context.setAttribute (object)
It's not a secret anymore!