| Author |
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 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
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,<br />T.Srinivasan,<br />SCWCD 1.4(89%),SCJP 5.0(75%)<br />"That service is the noblest which is rendered for its own sake." - Mahatma Gandhi
|
 |
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(); 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
Joined: Oct 18, 2005
Posts: 45
|
|
|
Thanks Promod
|
 |
 |
|
|
subject: Doubt regarding Headers
|
|
|