开发者

What happens to the output stream when I'm sending a file from a servlet to a browser?

I have an application which is used by users to download some files that are retrived unfortunately via a webservice.The webservice provide the content of the files inside the payload :(

So i might have a lot of documents simultaneously in the memory of the webapp thing that leads to out of memory.

The question is : when the user press on the webage download I start writing on the outputstream...but the user receives a popup with "save" or "cancel". What happens with the document until he press save ? What if he press cancel ?

The output stream is blocked 开发者_运维技巧on write until the user press save ?

Thanks...


No, the outputstream is not locked, it's buffered and it's sent to the client when your servlet container thinks it's the right time (or when you force sending with a flush() call on it).

Depending on your server infrastructure (if you have or not a reverse proxy in front of your web server) your request may fail or not, but usually you don't have to care about this.

And regarding the memory issue, you should probably call the web and either write directly as you read from it to the request output stream or you should write this to a file and then write this file in chunks to the response to avoid using too much memory and bringing the server down due to out of memory errors.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜