• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

addHeader & setHeader doubt

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if u have code like this


Will setHeader replace both values of "myHeader" or only last one? if i try request.getHeaders("myHeader") for the above response, what will i get, only "baz" or more than that.. Hope this is clear of what i am trying to ask?

Thanks & Regards,
Radmika
SCJP, SCBCD
 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is from API documentation


setHeader
public void setHeader(String name,
String value)
Sets a response header with the given name and value. If the header had already been set, the new value overwrites the previous one. The containsHeader method can be used to test for the presence of a header before setting its value.



Hope this helps.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SET means overriding existing value if exist else add value .
ADD means add value irrespective if name exist or not , if name did not exist creat name and add value to that name , If name Exist add one more value i.e NO overridding
 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I saw this question last night, and also got confused for this.
addHeader is like adding values to the header with the key.

the moment you call setHeader, it replaces all the values.

Also there is no getHeaders() method, but getHeader().
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Aruneesh Salhotra:
Also there is no getHeaders() method, but getHeader().



There is a getHeaders(String) method in the javax.servlet.http.HttpServletRequest interface. It returns a Enumeration of String containing all the values associated with the specified header.
 
Aruneesh Salhotra
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I misread the request.getHeaders() as
response.getHeaders().

I guess I assumed the question to be the same as yesterday mock test I took. (question 32)
 
A teeny tiny vulgar attempt to get you to buy our stuff
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic