当前位置: 技术问答>java相关
关于下载的问题:
来源: 互联网 发布时间:2015-09-05
本文导语: 各位大虾: 本人遇到这样一个问题: 代码如下: ..... response.setContentType("APPLICATION/OCTET-STREAM;charSet=GBK"); response.setHeader("Content-Disposition", "attachment; filename="" + filename + """); FileInputStream file = null; BufferedInputStream bis = n...
各位大虾:
本人遇到这样一个问题:
代码如下:
.....
response.setContentType("APPLICATION/OCTET-STREAM;charSet=GBK");
response.setHeader("Content-Disposition", "attachment; filename="" + filename + """);
FileInputStream file = null;
BufferedInputStream bis = null;
ServletOutputStream aaa = null;
BufferedOutputStream bos = null;
try
{
file=new FileInputStream(DLNAME);
}
catch(FileNotFoundException e)
{System.out.println("File is not found!");}
try
{
bis = new BufferedInputStream(file);
aaa=response.getOutputStream();
bos = new BufferedOutputStream (aaa);
byte[] buff = new byte[2048];
int bytesRead=0;
while((bytesRead = bis.read(buff, 0, buff.length))!=-1)
{
bos.write(buff, 0, bytesRead);
}
file.close();
bis.close();
aaa.close();
bos.close();
}
catch(IOException e){System.out.prinltn(e.getMessage());}
.....
如果正常下载是没有问题的.但如果在保存是选择关闭,则Web页变的非常慢.
希望各位高手帮帮忙!!!
谢谢!!!!!!!!!!!!!!!!!!!!!
本人遇到这样一个问题:
代码如下:
.....
response.setContentType("APPLICATION/OCTET-STREAM;charSet=GBK");
response.setHeader("Content-Disposition", "attachment; filename="" + filename + """);
FileInputStream file = null;
BufferedInputStream bis = null;
ServletOutputStream aaa = null;
BufferedOutputStream bos = null;
try
{
file=new FileInputStream(DLNAME);
}
catch(FileNotFoundException e)
{System.out.println("File is not found!");}
try
{
bis = new BufferedInputStream(file);
aaa=response.getOutputStream();
bos = new BufferedOutputStream (aaa);
byte[] buff = new byte[2048];
int bytesRead=0;
while((bytesRead = bis.read(buff, 0, buff.length))!=-1)
{
bos.write(buff, 0, bytesRead);
}
file.close();
bis.close();
aaa.close();
bos.close();
}
catch(IOException e){System.out.prinltn(e.getMessage());}
.....
如果正常下载是没有问题的.但如果在保存是选择关闭,则Web页变的非常慢.
希望各位高手帮帮忙!!!
谢谢!!!!!!!!!!!!!!!!!!!!!
|
“如果在保存是选择关闭,则Web页变的非常慢.”我想是应为你的读文件的代码还在执行,所以当然慢啦
变通个方法:
response.setContentType("application/octet-stream");
response.setStatus(response.SC_MOVED_TEMPORARILY);
response.setHeader("Location","/jsp/rowset-1_0-ea4.zip");
变通个方法:
response.setContentType("application/octet-stream");
response.setStatus(response.SC_MOVED_TEMPORARILY);
response.setHeader("Location","/jsp/rowset-1_0-ea4.zip");
|
能不能再获得客户端要求下载的信息后才执行上面的代码?
|
用jspSmartUpload吧!里面有许多现存的文件上传下载的bean!
下载地址:ftp.jspserver.com
用户名:guest
密码:guest
欢迎访问jsp技术论坛http://bbs.jspserver.com
下载地址:ftp.jspserver.com
用户名:guest
密码:guest
欢迎访问jsp技术论坛http://bbs.jspserver.com