Struts2导出Excel
来源:互联网 发布:惠州市教育局网络问政 编辑:程序博客网 时间:2024/05/21 10:57
1.首先是演示工程概览
2.struts.xml
浏览器输入http://localhost:8080/listArticles.action查询所有文章,返回articleList.jsp页。
3.articleList.jsp
点击链接“导出Excel”访问ArticleAction.java处理器类的exportArticle()方法。
4.ArticleAction.java
根据<action name="exportArticles"/>的配置,返回的输入流将从ArticleAction.java的getDownloadFile()负责得到。
getDownloadFile()方法调用了service层。
这里我直接把要导出的文件名定义在属性上了,开发中自己要根据业务去setDownloadFileName()。
5.ArticleService.java
6.ArticleServiceImpl.java
这里使用了ByteArrayOutputStream和ByteArrayInputStream,直接在内存中返回字节数组输入流,好处是不产生服务器的临时文件。
原先我使用FileOutputStream和FileInputStream来处理,还得开启线程延迟删除临时文件,考虑到这期间内服务器有可能关闭,所以又要写Servlet或者服务器启动定时任务来删除此类文件。颇为麻烦。
7.ArticleDao.java
8.applicationContext.xml
用了spring的自动装配<beans ... default-autowire="byName"/>,
这里略去dataSource、sessionFactory等配置。
9.web.xml
最终效果:
- struts2 导出excel
- struts2导出excel文件
- Struts2导出Excel
- struts2 导出excel
- struts2 导出excel
- Struts2导出Excel
- struts2导出excel笔记
- Struts2 poi导出excel
- Struts2 导出excel完整版
- struts2 导出excel
- struts2导出excel笔记
- struts2导出excel
- struts2导出excel java 导出excel
- struts2导出excel java 导出excel
- struts2 用jxl 导出excel
- struts2导出数据到Excel
- java/Struts2 jqgrid 导出excel
- struts2 使用注解 导出excel
- WindowManager的使用
- LINUX SOCKET programming by Example
- Linux下查看文件和文件夹大小的df和du命令
- gdi+笔记1之过滤图片透明色
- CTime
- Struts2导出Excel
- CFCA,SPKM
- 关于Nano-X
- Button中MouseLeftButtonDown和MouseLeftButtonUp事件无法触发的解决方案
- ExtJs性能优化
- OpenGL基本概念入门5——纹理贴图2
- [Android 界面] WindowManager的使用
- 一步步学汇编(十)标志寄存器
- boost 总结