dimanche 27 septembre 2015

Commit HttpServletResponse without output anything

I'm working on a web project(java + jsp). In my project there is a download function, which will call HttpServletResponse.getOutputStream() to write into a output stream and download the file. And afterwards I can call outputStream.flush() to commit the HttpServletResonse, and then the page stop loading.

In another module I want the same behavior: stop loading the page. I can do it with the following code:

OutputStream out = response.getOutputStream();
out.write(1);
out.flush();
out.close();

the whole page stops loading but one file(the "1") will be download. That is not what I want. I want nothing to be download. So I tried:

OutputStream out = response.getOutputStream();
out.flush();
out.close();

But in this case the page-loading didn't stop at out.flush(), but at out.close(), and the worst thing is the whole page turn blank. I'm a noob for web programming, and I really don't understand what is happening. Could anyone explain this to me? And what I want is the page stop loading but doesn't turn blank and doesn't download anything. Thank you!




Aucun commentaire:

Enregistrer un commentaire