File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes request headers question ... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "request headers question ..." Watch "request headers question ..." New topic

request headers question ...

Vassili Vladimir
Ranch Hand

Joined: Mar 08, 2007
Posts: 1585

Can anybody help me in this

This is one of the questions in the HFSJ final mock,

Which "a" will be set ? The second one or there will be only one header named "a" with the value of "c" ?

Thanks in advance ...

Vassili ...
SCJP 5.0, SCWCD 1.4, SCJA 1.0
Mark Garland
Ranch Hand

Joined: Nov 11, 2006
Posts: 226
addHeader adds the header to the existing value
setHeader replaces it.

So header 'a' will have the value of 'c' at the end of these lines.

28/06/06 - SCJP - 69%, 05/06/07 - SCWCD - 92%, 28/02/08 - IBM DB2 v9 Fundamentals (Exam 730) - 87%, 18/11/08 - IBM DB2 v9 DBA (Exam 731) - 89%, 26/02/11 - SCBCD - 88%
Vassili Vladimir
Ranch Hand

Joined: Mar 08, 2007
Posts: 1585
OK, I got it now

Thanks ...
Tanveer Ahmad
Ranch Hand

Joined: Sep 20, 2005
Posts: 33
addHeader & setHeader work like this... If "a" DOES NOT exist then "a" is set (NOTE here I have used SET... simple...). If "a" DOES exist then addHeader ADDS (menas add the existing value) but the setHeader SETS (means overwrite existing value).
So the answer will be "c", since last statement is setHeader("a", "c");
Had it been like addHeader("a", "c"); then outcome would be "abc".

Hope this helps.
Vassili Vladimir
Ranch Hand

Joined: Mar 08, 2007
Posts: 1585

It became even more clear, thanks Tanveer ...

Best of luck ...
It is sorta covered in the JavaRanch Style Guide.
subject: request headers question ...
Similar Threads
addHeader VS setHeader
How to solve refresh problem in JSP
response.addHeader() method
file name issue
page caching