• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Doubt regarding Headers

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Promod
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic