When the answer is complete, it means that at least the headers have already been sent to the client side. You cannot set / change the headers when the answer is already executed, because it is too late.
The response will be executed whenever one or more of the following conditions is true:
HttpServletResponse#sendRedirect() .- More than 2K has already been written to the output of the response, either using Servlet or using JSP.
- More than 0K, but less than 2K, was written, and
flush() was called in the response stream, either using a servlet or JSP.
The 2K buffer limit is configured in the application server configuration.
You need to rebuild the code logic so that it only sets the headers before the response is executed. You should never set / change response headers using scriptlets inside / half of the JSP. You should only do this in Filter before continuing the chain or in the Servlet page controller before sending the request. Also make sure that none of them are called by the JSP file.
Balusc
source share