Disable chunking per request

你。 提交于 2019-12-06 13:25:01

From the javadoc of HttpServlet#doGet():

...

Where possible, set the Content-Length header (with the ServletResponse.setContentLength(int) method), to allow the servlet container to use a persistent connection to return its response to the client, improving performance. The content length is automatically set if the entire response fits inside the response buffer.

When using HTTP 1.1 chunked encoding (which means that the response has a Transfer-Encoding header), do not set the Content-Length header.

...

So, if you set the response content length beforehand, then it won't be sent in chunked encoding.

response.setContentLength(contentLength);
// ...

Update: You also need to make sure that the servlet isn't in turn been called by <jsp:include> or RequestDispatcher#include(). See also its javadoc:

...

The ServletResponse object has its path elements and parameters remain unchanged from the caller's. The included servlet cannot change the response status code or set headers; any attempt to make a change is ignored.

...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!