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 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
Author

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:


Results:
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 ?

Thanks!

Angy.

SCJP 5
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1675
    
  25

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".

Regards,
Frits
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]}.

Servlet:


JSP:


Results:
myHeader:
myHeader2:


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

Joined: Mar 22, 2005
Posts: 41820
    
  62
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 :-)


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt about addHeader()