Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Explaination needed.

 
Stephen Nixon
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi - I'm sitting my exam next week and have been doing a few practice exams (just sat the HFSJ exam and just scraped the pass mark 64%!).

I have a query I hope someone may help me with.

The first is from the HFSJ exam:
Qu 55.

req.getSession().setAttribute("key", new X());
req.getSession().setAttribute("key", new X());
req.getSession().setAttribute("key", "x");

When we are setting the same attribute (in this case "key"), do we overwrite the existing one, or add to it?
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use setAttribute() you will always replace the old value with the new one... Headers in a response are slightly different: you can choose to use addHeader() rather than setHeader(), and they accept only String (not Object) values. For attributes (in any scope), there can only be one Object associated with a particular key (this is exactly the same as for a java.util.Map implementation).

I hope that helps...
[ October 06, 2006: Message edited by: Charles Lyons ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic