It's not a secret anymore!
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Doubt about addHeader() 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 about addHeader()" Watch "Doubt about addHeader()" New topic

Doubt about addHeader()

Fabian Angy
Ranch Hand

Joined: Oct 27, 2008
Posts: 90
Hi !

I have a problem with addHeader().

In my servlet:

In my JSP:

myHeader: first value

I don't understand why I have only "first value", where is the "second value" ?
If I do a "response.setHeader("myHeader", "third value") after the addHeader(), the setHeader() overrides the value and it's normal but why addHeader doesn't work ?.
What's wrong with this code ?



Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper

Joined: Apr 07, 2010
Posts: 2092

Hi Angy,

There is nothing wrong with your code, but the getHeader() method only gives you the first value.

To see all the values you could use the EL implicit object headerValues (a Map of HttpServletRequest header names and all values), like:
returns the third value of "Accept".

Fabian Angy
Ranch Hand

Joined: Oct 27, 2008
Posts: 90
My apologies !
Thank you !
Fabian Angy
Ranch Hand

Joined: Oct 27, 2008
Posts: 90
But.. in that case, if I do a setHeader()/addHeader() on the response, I can't acces to the value with ${headerValues.myHeader[0]}/${headerValues.myHeader[1]}.




Because the header is in the response and not in the request :/
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Note that request and response headers are different. What you're setting/adding are response headers, whereas headerValues is part of the request - so they're two completely different sets of headers.

Update: Which, I now see, you just figured out :-)
I agree. Here's the link:
subject: Doubt about addHeader()
jQuery in Action, 3rd edition