示例文件下载demo
页面:

后台:

package com.js.ai.modules.shwindow.util; import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @ClassName: DownloadCsv
* @Description: 下载 csv文件工具类
* @author:
* @date:
*/
public class DownloadCsv {
/**
*
* @Title: downloadCsv
* @Description: TODO下载 csv文件
* @param request
* @param response
* @param fileName
* @throws Exception * @return: void
*/
public static void downloadCsv(HttpServletRequest request, HttpServletResponse response,String fileName ) throws Exception{ response.setContentType("text/html;charset=UTF-8");
BufferedInputStream in = null;
BufferedOutputStream out = null;
request.setCharacterEncoding("UTF-8");
String rootpath = request.getSession().getServletContext().getRealPath("/");
try {
File f = new File(rootpath + "folder/" + fileName);
response.setContentType("application/x-excel");
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
response.setHeader("Content-Length", String.valueOf(f.length()));
in = new BufferedInputStream(new FileInputStream(f));
out = new BufferedOutputStream(response.getOutputStream());
byte[] data = new byte[1024];
int len = 0;
while (-1 != (len = in.read(data, 0, data.length))) {
out.write(data, 0, len);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
} }
示例文件下载demo的更多相关文章
- 文件下载Demo
知识点: //获取用户要下载的资源的名称 string name=context.Request.Params["downloadName"]; //设 ...
- golang使用http client发起get和post请求示例
[转自 http://www.01happy.com/golang-http-client-get-and-post/ ] get请求 get请求可以直接http.Get方法,非常简单. 1 2 3 ...
- bootstrap插件bootstrap-select使用demo
插件bootstrap-select官网 : https://developer.snapappointments.com/bootstrap-select/ bootstrap-select插件: ...
- Java并发包中CountDownLatch的工作原理、使用示例
1. CountDownLatch的介绍 CountDownLatch是一个同步工具,它主要用线程执行之间的协作.CountDownLatch 的作用和 Thread.join() 方法类似,让一些线 ...
- flex基础示例
flex的一些基础用法: <!-- Flex布局已经得到了所有浏览器的支持:chrome21+.Opera12.1+.Firefox22+.safari6.1+.IE10+ Webkit内核浏览 ...
- 近期热门微信小程序demo源码下载汇总
近期微信小程序demo源码下载汇总,乃小程序学习分析必备素材!点击标题即可下载: 即速应用首发!原创!电商商场Demo 优质微信小程序推荐 -秀人美女图 图片下载.滑动翻页 微信小程序 - 新词 GE ...
- pytorch 移动端框架 thnets 附c示例代码
前年年前做一个手机移动端图像识别项目的时候, 先后尝试了mxnet,thnets,caffe,tensorflow. 当时的情况是,mxnet内存管理奇差,内存经常由于模型运算分配不足,app挂掉. ...
- 跨平台移动开发 Adobe Edge制作HTML5圣诞音乐贺卡DEMO
1.新建项目 2.添加背景,图片,音频 var au_to_play=new Audio(); au_to_play.src="audio/lap.mp3"; //指定文件名,这里 ...
- 分享知识-快乐自己:Struts2文件上传及文件下载
1)Struts2单文件上传 action:类文件 package com.mlq.action; import com.opensymphony.xwork2.ActionSupport; impo ...
随机推荐
- webpack 打包图片 能否提高加载速度
正常加载: 打包图片: 结论:当加载资源 数量很多 时,可以提高加载速度
- python函数作用域
python中函数作用域 在python中,一个函数就是一个作用域 name = 'xiaoyafei' def change_name(): name = '肖亚飞' print('在change_ ...
- Git详解之八 Git与其他系统
以下内容转载自:http://www.open-open.com/lib/view/open1328070454218.html Git 与其他系统 世界不是完美的.大多数时候,将所有接触到的项目全部 ...
- Git学习的网址
http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 https://github.co ...
- notes on Art Pipeline
Do not add complex clothes/facial hair to a model for Mixamo to auto rig, it will cause confusion. A ...
- apk系统签名命令
java -jar signapk.jar platform.x509.pem platform.pk8 D:/ClockSetting.apk D:/ClockSettingSigned.apk 需 ...
- 使用python处理selenium中的xpath定位元素的模糊匹配问题
# 用contains,寻找页面中style属性值包含有sp.gif这个关键字的所有div元素,其中@后面可以跟该元素任意的属性名. self.driver.find_element_by_xpath ...
- Spark执行样例报警告:WARN scheduler.TaskSchedulerImpl: Initial job has not accepted any resources
搭建Spark环境后,调测Spark样例时,出现下面的错误:WARN scheduler.TaskSchedulerImpl: Initial job has not accepted any res ...
- 使用OPtional的orElse()问题
使用OPtional的orElse()问题 项目中有这样一段代码: return Optional.ofNullable(service.A()).orElse(service.B()) 1 功能显而 ...
- 关于上架AppStore最后一步的“出口合规信息”、“内容版权”、“广告标识符”的选择(转)
这里只当作记录:http://blog.csdn.net/ashimar_a/article/details/51745675