下载excel的问题 我现在是前台的下载的按钮,点击后请求到后台,动态生成excel文件(JXL方式),然后返回excel的路径。在前台用 window.open(response);返回的路径去打开要下载excel这样做出现了问题:下载的弹出界面总是要设置IE的下载的属性为启动。怎么才能不用设置IE啊,求教啊大家指导下我的怎么办?救急 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 就是我点击下载按钮,后台需要生产一个excel,需要弹出一个框,用户选择保存excel的路径。然而我用的IE的下载功能,传路径名、文件名。用 window.open(“这里是路径”)。这样要设置IE的浏览器属性,用户不希望这样,我要重改 我想这个需要ajax的文件流的传输,首先页面提交请求,然后服务器发送流,页面接受流,然后做转存处理,页面这部分都需要js实现,这个是解决方案,希望能帮到你 我在jsp页面上引用jxl的包,怎么都找不到啊,包导进了项目啊。<%@page import="jxl.Workbook"%>这样怎么不对啊 你引进的Workbook的包路径全么? 看看这篇文章,或许对你有帮助。http://blog.csdn.net/ilibaba/archive/2009/01/09/3741127.aspx 我现在是excel先生成在了服务器了。怎样把excel下载下来呢?我是这样弄的、前台:window.location.href="../receive_upload.jsp?type=download&excelPath='"+response+"'"; (response就是服务器上的路径地址)File showImg = new File("D:/workspace/ELink/webserver/webapps/ROOT/downexcel/tworkb2040.xls");byte[] buff = new byte[BUFFER_SIZE];int length = 0;InputStream fis = new FileInputStream(showImg);OutputStream fos = response.getOutputStream();while ((length = fis.read(buff)) != -1) { fos.write(buff, 0, length); }fis.close();fos.close(); public void downLoadExcel(){ logList = asdService.queryUploadLog(logDTO);//根据日志代码查询日志信息 byte[] importFile = logList.get(0).getImportFile();//取得日志信息中存储的Excel文件信息(数据库中是Blob,DTO中为byte[]) InputStream fis = new ByteArrayInputStream(importFile); String filename = logList.get(0).getImportFileName();//获取日志中存储的文件名称 HttpServletResponse response = (HttpServletResponse)ActionContext.getContext().get(org.apache.struts2.StrutsStatics.HTTP_RESPONSE);//获取response对象 try { int i = fis.available(); filename = new String(filename.getBytes("GBK"),"ISO8859_1"); //设置参数,使得浏览器弹出下载窗口 response.reset(); response.setContentType("application/octet-stream;charset=UTF-8"); response.setHeader("Accept-Ranges", "bytes"); response.setHeader("Accept-Length", (new Integer(i)).toString()); response.setHeader("Content-Disposition","attachment;filename="+filename); //读取流,送往客户端 byte[] bytes = new byte[4096]; int length = -1; while ((length = fis.read(bytes)) != -1) { response.getOutputStream().write(bytes, 0, length); } fis.close(); response.getOutputStream().close(); } catch (IOException e) { e.printStackTrace(); } public void downLoadFileByFilePath(String inFileName) { try { HttpServletResponse response = ServletActionContext.getResponse(); response.reset(); response.setContentType("APPLICATION/OCTET-STREAM"); /* * 要显示到客户端的文件名转码是必需的,特别是中文名, 否则可能出现文件名乱码甚至是浏览器显示无法下载的问题 */ String filePath = inFileName.substring( inFileName.lastIndexOf("/") + 1, inFileName.length()); filePath = response.encodeURL(new String(filePath.getBytes(), "ISO8859_1"));// 转码 response.setHeader("Content-Disposition", "attachment; filename=\"" + filePath + "\""); ServletOutputStream out = response.getOutputStream(); InputStream inStream = new FileInputStream(inFileName); // 循环取出流中的数据 byte[] b = new byte[1024]; int len; while ((len = inStream.read(b)) > 0) out.write(b, 0, len); response.setStatus(response.SC_OK); response.flushBuffer(); out.close(); out.flush(); inStream.close(); } catch (Exception e) { System.out.println(e); } } 直接打开Excel的URL(可以弹出窗口) 那种上网本用来学习JAVA程序够用么? 很棘手的问题,关于jdbc的问题,想了一个下午了,没调试出来,大虾们帮帮忙 Thinking in java 4th edition的问题 梦幻西游界面制作问题!耽误个位时间了。不好意思` 如何将byte[]数组转换成char[]数组?? 菜鸟求助:请帮忙解决一下 我运行书上java程序时的错误,看不明白,请高手指点! 关于BigDecimal的roundingMode的问题,谁能说说他们的区别? 这两种配置有什么区别? 字符串替换处理问题???谢谢 问一个小问题 含有return 的try catch finally的执行顺序!(很经典!)
然而我用的IE的下载功能,传路径名、文件名。用 window.open(“这里是路径”)。这样要设置IE的浏览器属性,用户不希望这样,我要重改
<%@page import="jxl.Workbook"%>
这样怎么不对啊
http://blog.csdn.net/ilibaba/archive/2009/01/09/3741127.aspx
我是这样弄的、前台:
window.location.href="../receive_upload.jsp?type=download&excelPath='"+response+"'"; (response就是服务器上的路径地址)File showImg = new File("D:/workspace/ELink/webserver/webapps/ROOT/downexcel/tworkb2040.xls");
byte[] buff = new byte[BUFFER_SIZE];
int length = 0;
InputStream fis = new FileInputStream(showImg);
OutputStream fos = response.getOutputStream();
while ((length = fis.read(buff)) != -1) {
fos.write(buff, 0, length);
}
fis.close();
fos.close();
public void downLoadExcel(){
logList = asdService.queryUploadLog(logDTO);//根据日志代码查询日志信息
byte[] importFile = logList.get(0).getImportFile();//取得日志信息中存储的Excel文件信息(数据库中是Blob,DTO中为byte[])
InputStream fis = new ByteArrayInputStream(importFile);
String filename = logList.get(0).getImportFileName();//获取日志中存储的文件名称
HttpServletResponse response = (HttpServletResponse)ActionContext.getContext().get(org.apache.struts2.StrutsStatics.HTTP_RESPONSE);//获取response对象
try {
int i = fis.available();
filename = new String(filename.getBytes("GBK"),"ISO8859_1");
//设置参数,使得浏览器弹出下载窗口
response.reset();
response.setContentType("application/octet-stream;charset=UTF-8");
response.setHeader("Accept-Ranges", "bytes");
response.setHeader("Accept-Length", (new Integer(i)).toString());
response.setHeader("Content-Disposition","attachment;filename="+filename);
//读取流,送往客户端
byte[] bytes = new byte[4096];
int length = -1;
while ((length = fis.read(bytes)) != -1) {
response.getOutputStream().write(bytes, 0, length);
}
fis.close();
response.getOutputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
try {
HttpServletResponse response = ServletActionContext.getResponse();
response.reset();
response.setContentType("APPLICATION/OCTET-STREAM");
/*
* 要显示到客户端的文件名转码是必需的,特别是中文名, 否则可能出现文件名乱码甚至是浏览器显示无法下载的问题
*/
String filePath = inFileName.substring(
inFileName.lastIndexOf("/") + 1, inFileName.length());
filePath = response.encodeURL(new String(filePath.getBytes(),
"ISO8859_1"));// 转码
response.setHeader("Content-Disposition", "attachment; filename=\""
+ filePath + "\"");
ServletOutputStream out = response.getOutputStream();
InputStream inStream = new FileInputStream(inFileName);
// 循环取出流中的数据
byte[] b = new byte[1024];
int len;
while ((len = inStream.read(b)) > 0)
out.write(b, 0, len);
response.setStatus(response.SC_OK);
response.flushBuffer();
out.close();
out.flush();
inStream.close();
} catch (Exception e) {
System.out.println(e);
}
}