jQuery in Action, 3rd edition
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Doubt  regarding Headers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Doubt  regarding Headers" Watch "Doubt  regarding Headers" New topic

Doubt regarding Headers

Raj Menon
Ranch Hand

Joined: Oct 18, 2005
Posts: 45
Hi everybody,

In the HFSJ mock exam 32nd question

It is given as


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

Joined: Feb 15, 2007
Posts: 557
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.

Thanks & Regards, T.Srinivasan
SCWCD 1.4(89%), SCJP 5.0(75%)
Raj Menon
Ranch Hand

Joined: Oct 18, 2005
Posts: 45
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

Joined: Jun 26, 2006
Posts: 90
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();

At this point you have a key with values list with two values.
Now if you do something like

The last statement will give you "newString", the list is gone. Hope that helps.
Raj Menon
Ranch Hand

Joined: Oct 18, 2005
Posts: 45
Thanks Promod
I agree. Here's the link: http://aspose.com/file-tools
subject: Doubt regarding Headers
It's not a secret anymore!