This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Servlets and the fly likes setHeader() and addHeader() methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "setHeader() and addHeader() methods" Watch "setHeader() and addHeader() methods" New topic

setHeader() and addHeader() methods

Vijayanarayana Reddy Bhoomireddy

Joined: Apr 22, 2006
Posts: 6

I have a query regarding the setHeader() and addHeader() methods belonging to the HttpServletResponse class.

If the header is 'content-type' and already the header exists in the response, then setHeader() will replace the value of the existing content-type with the new value.

But how does the addHeader() method work for content-type? I think browser will be able to recognize only one content type at a time i.e. content-type header cannot have more than one value.

Please let me know how this works or correct me if I'm wrong in my understanding.

Many Thanks
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42359
Weclome to JavaRanch.

This is one of the things that you can easily test: whether the first header takes precendence, the second, both, none, or something else. What happened when you tried it?

Ping & DNS - my free Android networking tools app
It is sorta covered in the JavaRanch Style Guide.
subject: setHeader() and addHeader() methods