我的Excel文件已经生成,并且文件生成的路径我已经能获取到。现在我要实现以下功能,弹出一个对话框让(图1)用户选择 路径,将我文件保存到用户指定的路径(图2) 应该怎么做?
[img]/upload/attachment/63850/12479d0f-4293-3393-a292-4b32b808d06b.bmp[/img] 图1
[img]/upload/attachment/63852/132a6228-30d9-343c-934e-2ecc4ad4818c.bmp[/img] 图2
[b]问题补充:[/b]
我excel 已经是文件了,不是流了。
我尝试过 直接到我的excel但是不行,
response.redirect("aa.xls") 也不行。
换个角度想就是如何让 客户端访问服务器端的 文件? 用服务器的绝对路径应该可以,比如:file:///D:/DEV/project/islpv21/islpblv2/WebContent/temp//1230528078515.xls
但是我却访问不到。
[code="java"]
response.setHeader("Content-Disposition","attachment;filename=" + file);
byte[] buf = new byte[8196];
int len;
ServletOutputStream sos = response.getOutputStream();
while ((len = is.read(buf)) != -1) {
sos.write(buf, 0, len);
}
sos.flush();
sos.close();
is.close();
[/code]
这样就可以搞定了!把你写好的文件当附件的下载下去就可以了!
在web.xml文件中加上下面代码
[code="java"]
xls
application/xls
[/code]
把下载的那个JSP文件的responsetype改成强制下载类型就可以了。
这样:
[code="java"]
<%@ page language="java" pageEncoding="UTF-8" contentType="application/force-msdownload" %>
[/code]
然后以流动形式写出去就ok
[code="java"]
String fileName=MimeUtility.decodeText(nameList.get(Integer.parseInt(fileIdStr)));
response.addHeader("Content-Disposition","attachment;filename=" +fileName);
try {
int count=0;
byte[] data=new byte[512];
while( (count=(input.read(data)))>0 ) {
output.write(data,0,count);
}
output.flush();
}catch(IOException ex) {
System.out.println("出现异常:"+ex.getMessage());
}finally {
input.close();
output.close();
}
[/code]