spring mvc实现下载一个excel文件的java web程序
1.设置文件名
String fileName="batch_fund_template.xls";
2设置ContentType
response.setContentType("application/vnd.ms-excel");
3.设置文件路径
String nowPath=request.getSession().getServletContext().getRealPath("/")+"/"+"WEB-INF"+"/"+"template"+"/"+fileName;
4.新建文件对象
File file=new File(nowPath);
5.清空response
response.reset();
6.设置response的header
response.addHeader("Content-Disposition", "attachment;filename="+new String(fileName.getBytes("gbk"),"iso-8859-1"));
response.addHeader("Content-Length", ""+file.length());
7.以流的方式下载文件
InputStream fis=new BufferedInputStream(new FileInputStream(nowPath));
byte[] buffer=new byte[fis.available()];
fis.read(buffer);
fis.close();
toClient=new BufferedOutputStream(response.getOutputStream());
toClient.write(buffer);
toClient.flush();
toClient.close();
项目截图
运行截图
猜你喜欢
- spring mvc导出excel、csv、access、sql等文件格式
- SpringMvc从propertites属性文件读取常量
- spring mvc文件上传与下载实例
- spring mvc+easyui开发文件上传下载实例demo源码下载
- spring mvc+Maven+ZUI可拖拽多个文件上传和下载实例
- struts2 poi导出excel实例代码下载
- golang读取excel文件生成SQL语句
- java实现html网页转excel文件
- java转换excel为pdf文件
- apache poi导出Excel或Pdf文件的工具类
- springMVC注解与hibernate完美结合完成基本的增删改查demo源码下载
- springboot整合easyexcel实现excel文件上传解析,下载导出简单实例
- /
- /export
- /export/.classpath
- /export/.project
- /export/.settings
- /export/.settings/.jsdtscope
- /export/.settings/org.eclipse.core.resources.prefs
- /export/.settings/org.eclipse.jdt.core.prefs
- /export/.settings/org.eclipse.m2e.core.prefs
- /export/.settings/org.eclipse.wst.common.component
- /export/.settings/org.eclipse.wst.common.project.facet.core.xml
- /export/src
- /export/src/main
- /export/src/main/java
- /export/src/main/java/com
- /export/src/main/java/com/web
- /export/src/main/java/com/web/controller
- /export/src/main/java/com/web
- /export/src/main/java/com
- /export/src/main/java
- /export/src/main
- /export/target
- /export/target/tomcat
- /export/target/tomcat/work
- /export/target/tomcat/work/Tomcat
- /export/target/tomcat/work/Tomcat/localhost
- /export/target/tomcat/work/Tomcat/localhost/export
- /export/target/tomcat/work/Tomcat/localhost/export/org
- /export/target/tomcat/work/Tomcat/localhost/export/org/apache
- /export/target/tomcat/work/Tomcat/localhost/export/org/apache/jsp
- /export/target/tomcat/work/Tomcat/localhost/export/org/apache/jsp/WEB_002dINF
- /export/target/tomcat/work/Tomcat/localhost/export/org/apache/jsp/WEB_002dINF/jsp
- /export/target/tomcat/work/Tomcat/localhost/export/org/apache/jsp/WEB_002dINF
- /export/target/tomcat/work/Tomcat/localhost/export/org/apache/jsp
- /export/target/tomcat/work/Tomcat/localhost/export/org/apache
- /export/target/tomcat/work/Tomcat/localhost/export/org
- /export/target/tomcat/work/Tomcat/localhost/export
- /export/target/tomcat/work/Tomcat/localhost
- /export/target/tomcat/work/Tomcat
- /export/target/tomcat/work
- /export/target/tomcat
- /export
- 证精 基于浏览器首选语言的springmvc和freemarker国际化配置的实现
- 原 基于maven与springMVC的拦截器Interceptor,控制器Controller的使用
- springmvc @RequestMapping注解的入门配置教程
- 精 SpringMVC的三种统一异常处理实例代码分享
- 证精 bootstrap jquery underscore backbone 新浪微博 springmvc整合demo代码
- 精 spring mvc-showcase,便于学习springmvc,maven工程,建议使用谷歌浏览器
- 原证精 springmvc @RequestMapping注解伪静态技术
- 原 springMVC注解与hibernate完美结合完成基本的增删改查demo源码下载
- 原 SpringMVC整合Redis demo小例子
- 原证精 java Web SpringMVC项目实现12306余票查询功能
- 原证 springmvc开发微信公众平台验证token接口教程及其java源代码分享
- 原 SpringMvc整合Mybatis搭建java Web入门项目实例,是基于MAVEN的java web工程