springMVC利用poi导出excel,下载框为什么总是弹不出来?百度了N久了,主代码在下面。 100
wb是poi的HSSFWorkbook,excel生成确认没问题,导出到本地也正常,就是弹不出下载框,求解答。...
wb是poi的HSSFWorkbook,excel生成确认没问题,导出到本地也正常,就是弹不出下载框,求解答。
展开
展开全部
要不给你一个可以直接调用的方法吧,你也可以对比修改
/**
* 下载文件
*
* @param request
* @param response
* @param storeName 被下载文件路径
* @param contentType 推荐:application/octet-stream
* @param realName 下载时显示的文件名称
* @throws Exception
*/
public static void download(HttpServletRequest request, HttpServletResponse response, String storeName, String contentType, String realName)
throws Exception {
request.setCharacterEncoding("UTF-8");
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
String downLoadPath = storeName;
long fileLength = new File(downLoadPath).length();
response.setContentType(contentType);
response.setHeader("Content-disposition", "attachment; filename=" + new String(realName.getBytes("utf-8"), "ISO8859-1"));
response.setHeader("Content-Length", String.valueOf(fileLength));
bis = new BufferedInputStream(new FileInputStream(downLoadPath));
bos = new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesRead);
}
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询