• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt regarding Headers

 
Raj Menon
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,

In the HFSJ mock exam 32nd question

It is given as

response.addHeader("myheader","foo");
response.addHeader("myheader","bar");
response.setHeader("myheader","baz");


In this one which header value("foo" or "bar") will be
overridden with "baz" because of setHeader method call?

Thanks in Advance...
[ August 08, 2007: Message edited by: Rajesh Kodali ]
 
Srinivasan thoyyeti
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rajesh,

response.addHeader(name,value) allows us to multiple values for the same name.

1. response.addHeader("myheader","v1"); --> value(s) v1.
2. response.addHeader("myheader","v2"); --> value(s) v1,v2

response.setHeader(name,value) replaces the value(s) associated with exising name (or) creates a new (name,value).

3.response.setHeader("myheader","BOO"); --> value(s) BOO

finally myheader value is BOO.
 
Raj Menon
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Srinivasan,

That means by calling the setHeader method, we are erasing all the values if any exists with that Header name and a new value will be saved for that Header name,right?
 
Promod kumar
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the way I think about it is a Hashmap.This is only for conceptualization, I don't know exactly how it is implemented.

Map map = new HashMap();
List values = new ArrayList();
values.add("firstValue");
values.add("secondValue");
map.put("header",values);

At this point you have a key with values list with two values.
Now if you do something like
map.put("header","newString");
map.get("header");

The last statement will give you "newString", the list is gone. Hope that helps.
 
Raj Menon
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Promod
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic