The container itself decides to use Content-Length or Transfer-Encoding based on the size of the data to be written using Writer or outputStream . If the data size is larger than HttpServletResponse.getBufferSize() , then the response will be broadcast. If not, Content-Length will be used.
In your case, just delete the second cleanup code, solving your problem.
source share