private static void writeData( byte[] file, HttpServletResponse response )
throws IOException
{
....
// Send the data
response.setContentLength(file.length);
response.getOutputStream().write(file);
}
最近,我在IE8中发现一些连接在请求下载文件时会关闭。这是相关的源代码,我想知道是否一次将大字节数组写入响应输出流会导致这个问题。这个问题是非常不可复制的,我经常看到这样的模式:一次写入一定数量的字节,而不是一次写入所有字节,以避免MTU问题,或者类似的问题。
编辑:
我试过用
Cache-Control: no-cache
请求:
POST /myapplication/someAction.do?step=none&SAct=none HTTP/1.1
Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/x-shockwave-flash, */*
Referer: https://myhost.myhost.com/myapplication/someAction.do?queryString=something
Accept-Language: en-US
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MS-RTC LM 8; .NET4.0C; InfoPath.3)
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Host: myhost.myhost.com
Content-Length: 1644
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: JSESSIONID=GnvHMYyGx9QrmpVQfBSgNXnPM8nQJ21dT82KhmSSTXRRT1mgB8tP!299858932; [truncated]
答复:
HTTP/1.1 200 OK
Cache-Control: no-cache
Date: Tue, 21 Sep 2010 18:00:56 GMT
Transfer-Encoding: chunked
Content-Type: application/ZIP
Content-Disposition: inline; filename=ActivityReport.ZIP
X-Powered-By: Servlet/2.5 JSP/2.1