开发者

tomcat 6 . How does HttpServletResponse make browsers react immediately , not have done response.getOutputStream().close()??

This is the code in my servlet:

while( bytes....){//do read file to bytes
    response.getOutputStream().write(bytes);
    response.getOutputStream().flush();
    log4j.debug(response.isCommitted());  // out  true.
}

If my file is 100MB , the server must read 100MB to memory and 开发者_JAVA百科then the browser alerts a dialog of downloading file. How the waiting time of the browser terrible, when my file is gt than 2GB ....


Browser compatibility problems, from Servlet Best Practices, Part 3 by The O'Reilly Java Authors:

The bad news is that although the HTTP specification provides a mechanism for file downloads (see HTTP/1.1, Section 19.5.1), many browsers second-guess the server's directives and do what they think is best rather than what they're told.

The good news is that the right combination of headers will download files well enough to be practical. With these special headers set, a compliant browser will open a Save As dialog, while a noncompliant browser will open the dialog for all content except HTML or image files.

set the Content-Type header to a nonstandard value such as application/x-download.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜