简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM