Search code examples
javaservletsjakarta-ee

What is the difference between Servlet response methods addHeader and setHeader?


Can I use setHeader to set an new header?
Or Do I need to addHeader first, then use setHeader method?


Solution

  • The documentation says that you can add multiple values to a particular header using the addHeader method, whereas an initial value would be overwritten if you use the setHeader method.

    In both cases a non-existent header would be created.