File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Doubt  regarding Headers" Watch "Doubt  regarding Headers" New topic
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, 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();
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt regarding Headers
 
Similar Threads
setHeader() doubt
Exam question - is a , has a- help!
how to compile java files in different packages same time in LINUX system
addHeader & setHeader doubt
PGJC Exam - clarification?