我有下面的一段代码:
public static void sendDutyTableTemplateBytes(HttpServletRequest request, HttpServletResponse response) throws IOException, SQLException, NamingException
{
String fileName = "duty_table.xls";
response.reset();
response.setContentType(ContentType.content_type_excel_2003);
response.addHeader("Content-Disposition", "attachment; filename=\""+fileName+"\"");
OutputStream out = response.getOutputStream();
InputStream inStream = null;
try {
inStream = request.getSession().getServletContext().getResourceAsStream("/security/templates/"+fileName);
byte[] b = new byte[1024];
int i = 0;
while((i = inStream.read(b)) > 0) {
out.write(b, 0 ,i);
}
} finally {
if( inStream!=null ){
inStream.close();
}
if( out!=null ){
out.close();
}
}
}
它的功能是:在war里面获取一个文件的流,然后就这个流写向response.getOutputStream()
这样客户端就可以下载到这个文件了.
在客户端使用ie的时候能够正常的下载到文件,使用google浏览器也正常,但是客户端使用firefox的时候却不能下载文件.请问大侠们这个问题怎么解决?
public static void sendDutyTableTemplateBytes(HttpServletRequest request, HttpServletResponse response) throws IOException, SQLException, NamingException
{
String fileName = "duty_table.xls";
response.reset();
response.setContentType(ContentType.content_type_excel_2003);
response.addHeader("Content-Disposition", "attachment; filename=\""+fileName+"\"");
OutputStream out = response.getOutputStream();
InputStream inStream = null;
try {
inStream = request.getSession().getServletContext().getResourceAsStream("/security/templates/"+fileName);
byte[] b = new byte[1024];
int i = 0;
while((i = inStream.read(b)) > 0) {
out.write(b, 0 ,i);
}
} finally {
if( inStream!=null ){
inStream.close();
}
if( out!=null ){
out.close();
}
}
}
它的功能是:在war里面获取一个文件的流,然后就这个流写向response.getOutputStream()
这样客户端就可以下载到这个文件了.
在客户端使用ie的时候能够正常的下载到文件,使用google浏览器也正常,但是客户端使用firefox的时候却不能下载文件.请问大侠们这个问题怎么解决?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货