Section SRV.5.2 Headers for Java โข Version Servlet Specification Version 2.4
To be successfully transferred to the client, headers must be set before the response is complete. The headers set after the response will be ignored by the servlet container.
Thus, the specification does not explicitly mention getWriter()
, which affects header settings.
However, the implementation of your servlet container can be selected to handle the response as incoming after calling getWriter()
. This is a little different.
In some containers that I worked with, you get a warning that is logged when you try to set the header after the response is completed.
You should always call getWriter()
as late as possible, as you may need to set the character encoding, etc. that must be set before calling getWriter()
.
source share