说明: 上传文件保存在服务器的本地盘符的一个文件夹中,文件名已经更换为系统自动产生的序列号(变量为:filebh).下载中必须更换改文件的名称即定义的一个默认的该文件名称(非序列号,是,为:tempFileName),当然在客户端的提示窗口中用户可以自定义文件名.
问题:在弹出提示框中,点击直接"打开",系统提示该文件没找到!找的文件为默认的文件名称的文件[1],怎么样进行设置!即打开时IE未缓存到该该客户端的零时文件夹中!
public boolean loadData(String filebh,final HttpServletResponse response,String tempFileName){
if(filebh==null) filebh="";
BufferedOutputStream bos = null;
StringBuffer sb = new StringBuffer(50);
sb.append("attachment; filename=");
sb.append(tempFileName);
String serverloadPath=ReadConfig.getUpload();
serverloadPath=serverloadPath+filebh;
try{
if(serverloadPath!= null) {
response.setContentType("application/x-msdownload;charset=gb2312");
response.setHeader("Content-Disposition", new String(sb.toString()
.getBytes(), "ISO8859-1"));
FileInputStream fis = new FileInputStream(serverloadPath);
bos = new BufferedOutputStream(response.getOutputStream());
byte[] buffer = new byte[8192];
while(fis.read(buffer) != -1) {
bos.write(buffer);
}
bos.write(buffer,0,buffer.length);
bos.close();
fis.close();
}
}catch(Exception ex) {
System.out.print(ex);
}
return true;
}
问题:在弹出提示框中,点击直接"打开",系统提示该文件没找到!找的文件为默认的文件名称的文件[1],怎么样进行设置!即打开时IE未缓存到该该客户端的零时文件夹中!
public boolean loadData(String filebh,final HttpServletResponse response,String tempFileName){
if(filebh==null) filebh="";
BufferedOutputStream bos = null;
StringBuffer sb = new StringBuffer(50);
sb.append("attachment; filename=");
sb.append(tempFileName);
String serverloadPath=ReadConfig.getUpload();
serverloadPath=serverloadPath+filebh;
try{
if(serverloadPath!= null) {
response.setContentType("application/x-msdownload;charset=gb2312");
response.setHeader("Content-Disposition", new String(sb.toString()
.getBytes(), "ISO8859-1"));
FileInputStream fis = new FileInputStream(serverloadPath);
bos = new BufferedOutputStream(response.getOutputStream());
byte[] buffer = new byte[8192];
while(fis.read(buffer) != -1) {
bos.write(buffer);
}
bos.write(buffer,0,buffer.length);
bos.close();
fis.close();
}
}catch(Exception ex) {
System.out.print(ex);
}
return true;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货