Get rid of
response.flushBuffer();
which commits the response.
The Servlet container will take care of committing the response and flushing the OutputStream
when it needs to.
If your file is too big, you'll want to create the session yourself before starting the download.
To answer comment:
It seems you never created an HttpSession
during your request handling.
The container's implementation of HttpServletResponse
commits the response (headers) and starts flushing the OutputStream
when you've written X amount of bytes (configurable and depends on container). You cannot force the container to create an HttpSession
after that's happened.
Obviously you weren't creating the HttpSession
yourself, but Spring uses it to manage its model attributes, so it had to create it. It does that in
at org.springframework.web.method.annotation.ModelFactory.updateModel(ModelFactory.java:202) [spring-web-3.2.2.RELEASE.jar:3.2.2.RELEASE]
The simple solution is to get a reference to the HttpServletRequest
and call its getSession(boolean)
method, passing true
so that it forces the creation of the HttpSession
. Do this anywhere before you start pushing the file.