Hai Anand
I was also kicking myself to get an answer to your question.
I totally agree with your previous post. My earlier posts were S... well you know what.
The Servlet API Javadocs for HttpServletResponse's setHeader() method says that
"Sets a response header with the given name and value. If the header had already been set, the new value overwrites the previous one."
Overwrites, which "previous one" is ambiguous too. Is the value that has been set by a previous setHeader() method overwritten or the value set by the first addHeader() method overwritten.
I thought may be a step by step
testing of the program could lead me somewhere. I got these results so far (with changes to your program).
the result was
This is pretty well expected.
But if i add an addHeader() method in between the two see what happens,
for the following code
The result is
C:\>java HeaderTest
Key = [h2] Value = [add two,set one]
Key = [Content-Length] Value = [0]
Key = [h1] Value = [add another value to the header,overwrite previous]
Key = [Date] Value = [Wed, 20 Apr 2005 05:15:01 GMT]
Key = [Server] Value = [Apache-Coyote/1.1]
Key = [null] Value = [HTTP/1.1 200 OK]
So I agree with Todd over this. Only the first value to be set is being overwritten by using a setHeader for a header which already has multiple values.
Neither the API nor the specs warn you about using a setHeader after using an addHeader. The docs for addHeader just inform that this method makes it possible for a header to have multiple values.
So this may be the expected behavior. I'm trying to go through the tomcat code to see if I can find something. All I see so far is calls to coyoteResponse.setHeader() and coyoteResponse.addHeader(). I'm hunting for the coyoteResponse thing.