文件下载servlet与群集服务器上的IE表现不同

时间:2022-11-11 22:34:47

I have a servlet that sends a file by setting the HTTP Content-Type to "application/zip", the Content-Disposition to "attachment" and writing it on the response's OutputStream; it behaves correctly when deployed on my local application server, making the browser show the popup to choose wheter or not to download the file.

我有一个servlet,通过将HTTP Content-Type设置为“application / zip”,将Content-Disposition设置为“attachment”并将其写入响应的OutputStream来发送文件;在我的本地应用程序服务器上部署时,它的行为正确,使浏览器显示弹出窗口以选择是否下载文件。

However, when deploying on a clustered jboss server, IE hangs on 0% requesting file information for the whole transfer and then fails with an error message stating that the file wasn't available for download: even stranger is the fact that with FF and Chrome the servlet behaves correctly, i.e. same way as on localhost.

但是,当在集群jboss服务器上部署时,IE挂起0%请求整个传输的文件信息,然后失败并显示一条错误消息,指出该文件无法下载:甚至更奇怪的是,使用FF和Chrome servlet行为正确,即与localhost相同。

Any clues?

I can also provide a small snippet of the significant part of the servlet code:

我还可以提供servlet代码重要部分的一小部分:

response.setContentType("application/zip; name=" + f.getName());
response.setContentLength((int)f.length());     
response.addHeader("Content-Disposition", "attachment;filename=" + f.getName());
byte[] buf = new byte[1024];
int bytesRead;
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f));
OutputStream os = response.getOutputStream();
while((bytesRead = bis.read(buf)) != -1) {
    os.write(buf, 0, bytesRead);                
}
os.flush();
bis.close();

I don't really know if the problem lies in my servlet code or in the clustered server configuration, but i'm starting to guess the second chance may be the right one...any ideas on what could be wrong in my cluster configuration?

我真的不知道问题出在我的servlet代码或集群服务器配置中,但我开始猜测第二次机会可能是正确的......任何关于我的集群配置可能出错的想法?

2 个解决方案

#1


This is possibly a result of IE behaviour described in these articles:

这可能是这些文章中描述的IE行为的结果:

http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B181050

http://support.microsoft.com/default.aspx/kb/813827

I had a similar problem (only with Tomcat), which only occurred if the file size was large enough. You can easily test if that is the case by measuring the time from starting the download to the error message - if that time is constant, you have probably the same error. You don't possibly see the error locally, because the files load fast enough.

我遇到了类似的问题(仅限Tomcat),只有在文件大小足够大时才会出现问题。您可以通过测量从开始下载到错误消息的时间来轻松测试是否是这种情况 - 如果该时间不变,则可能存在相同的错误。您不可能在本地看到错误,因为文件加载速度足够快。

If the timeout results from the time generating the file, one solution would be to create the file in an asynchronous manner and start the download first after the file is ready to be downloaded.

如果超时是由生成文件的时间产生的,一种解决方案是以异步方式创建文件,并在文件准备好下载后首先开始下载。

#2


Ok, i fixed it.

好的,我修好了。

The load balancer standing between the client and the individual cluster servers was adding 'Cache-Control: no-cache' to every HTTP response, which caused IE to get mad.

站在客户端和各个集群服务器之间的负载均衡器正在为每个HTTP响应添加“Cache-Control:no-cache”,这导致IE生气。

Removing the header directive solved the problem.

删除header指令解决了这个问题。

#1


This is possibly a result of IE behaviour described in these articles:

这可能是这些文章中描述的IE行为的结果:

http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B181050

http://support.microsoft.com/default.aspx/kb/813827

I had a similar problem (only with Tomcat), which only occurred if the file size was large enough. You can easily test if that is the case by measuring the time from starting the download to the error message - if that time is constant, you have probably the same error. You don't possibly see the error locally, because the files load fast enough.

我遇到了类似的问题(仅限Tomcat),只有在文件大小足够大时才会出现问题。您可以通过测量从开始下载到错误消息的时间来轻松测试是否是这种情况 - 如果该时间不变,则可能存在相同的错误。您不可能在本地看到错误,因为文件加载速度足够快。

If the timeout results from the time generating the file, one solution would be to create the file in an asynchronous manner and start the download first after the file is ready to be downloaded.

如果超时是由生成文件的时间产生的,一种解决方案是以异步方式创建文件,并在文件准备好下载后首先开始下载。

#2


Ok, i fixed it.

好的,我修好了。

The load balancer standing between the client and the individual cluster servers was adding 'Cache-Control: no-cache' to every HTTP response, which caused IE to get mad.

站在客户端和各个集群服务器之间的负载均衡器正在为每个HTTP响应添加“Cache-Control:no-cache”,这导致IE生气。

Removing the header directive solved the problem.

删除header指令解决了这个问题。