Adding a cookie requires modifying the HTTP headers of the response. Once the response has been "committed", e.g. anything written to the output stream, you can not modify the HTTP headers. The response has been committed by the time you try to add your cookie. [originally posted on jforum.net by monroe]
Most JSP implimentations and some servlets will actually generate the response in a buffer. This means the response isn't committed the output is closed or manually flushed. So, this would work in some applications and not in others.
I imagine that the either jForum or the Template engine does a specific flush of the output stream at some point.
FWIW, there is also a JSP page directive to set the buffer size and turn on autoflush. These are useful for long running pages that you want users to see some status info coming back. Your cookie setting method would fail for pages like these too.
[originally posted on jforum.net by monroe]
My pie came with a little toothpic holding up this tiny ad: