- 浏览: 226015 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
插上翅膀的小猪:
同意三楼的意见。
下载服务器上的文件-纯java处理 -
ITQCF:
一楼所言极是啊,encodeFileName这个方法为嘛找不到 ...
下载服务器上的文件-纯java处理 -
u011296404:
这个不适用与ie浏览器
下载服务器上的文件-纯java处理 -
冬天秋天:
博主 这个貌似在oracle 数据库下没有成功啊……
更新一个表的字段值等于另一个表的字段值的SQL语句 -
pangpang514:
WebUtils是在org.springframework.w ...
下载服务器上的文件-纯java处理
目的:实现从前端到后台及生成报表的整个流程。
1.jsp页面
<%@page contentType="text/html; charset=UTF-8"%> <%@ include file="/commons/taglibs.jsp"%> <html> <head> <title>生成报表</title> <script language="JavaScript" type="text/JavaScript"> function doPrintHTML(id) { window.open("${ctx}/expense/expTrack.do?method=doPrintHTML&id="+id); } function doPrintPDF(id) { window.open("${ctx}/expense/expTrack.do?method=doPrintPDF&id="+id); } </script> </head> <div align=center> <ec:table items="explist" var="exp" action="${ctx}/expense/expTrack.do" imagePath="${ctx}/widgets/extremecomponents/images/newHR/*.gif" retrieveRowsCallback="limit" view="newHr"> <ec:row highlightClass="newHrECRowHighlightClass"> <ec:column property="null" title="打印明细" sortable="false" viewsAllowed="newHr"> <a href="javascript:doGetExpItem('${exp.id}');" style="TEXT-DECORATION: none"><img src="${ctx}/styles/newHR/images/detail2.gif" alt="明细html详情" border="0"> </a> <a href="javascript:doPrintPDF('${exp.id}');" style="TEXT-DECORATION: none"><img src="${ctx}/styles/newHR/images/print.gif" alt="明细PDF详情" border="0"> </a> </ec:column> </ec:row> </ec:table> </div> </div> </body> </html>
2.Struts中action 中的代码编写
打印pdf的
public ActionForward doPrintPDF(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { try { String empName = "name"; Float totalAmountTemp =780; //数据转换 DecimalFormat df = new DecimalFormat("0.00"); String totalAmount = df.format(totalAmountTemp); //数据转换-End String path = servlet.getServletContext().getRealPath("/"); path = path + "report\\image\\logo.jpg"; HashMap<String,String> parameters = new HashMap<String, String>(); parameters.put("EMPLOYEE_NAME", empName); parameters.put("TOTAL_AMOUNT", totalAmount); parameters.put("IMG_PATH_LOGO", path); List<ItemsVO> resultList = itemsService.findItemByExp(); expPrintService.showPDFPage(request, response, parameters, resultList, "PteExpend"); }catch (BusinessException e) { saveDirectlyError(request,e.getMessage()); log.error(e); } catch (Exception e) { String message = ""; saveDirectlyError(request,message); log.error(message+e); } return null; }
打印html
public ActionForward doPrintPDF(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { try { String empName = "name"; Float totalAmountTemp =780; //数据转换 DecimalFormat df = new DecimalFormat("0.00"); String totalAmount = df.format(totalAmountTemp); //数据转换-End String path = servlet.getServletContext().getRealPath("/"); path = path + "report\\image\\logo.jpg"; HashMap<String,String> parameters = new HashMap<String, String>(); parameters.put("EMPLOYEE_NAME", empName); parameters.put("TOTAL_AMOUNT", totalAmount); parameters.put("IMG_PATH_LOGO", path); List<ItemsVO> resultList = itemsService.findItemByExp(); expPrintService.showHTMLPage(request, response, parameters, resultList, "PteExpend"); }catch (BusinessException e) { saveDirectlyError(request,e.getMessage()); log.error(e); } catch (Exception e) { String message = ""; saveDirectlyError(request,message); log.error(message+e); } return null; }
调用的子方法
@SuppressWarnings("deprecation") public void showPDFPage(HttpServletRequest request, HttpServletResponse response, Map<String, String> parameters, List<?> resultList, String reportModuleName) throws IOException{ try { File reportFile = new File(request.getRealPath("/report/" + reportModuleName +".jasper")); JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(resultList); String reportFilePath = reportFile.getPath(); JasperPrint jasperPrint; jasperPrint = JasperFillManager.fillReport(reportFilePath, parameters, ds); byte[] bytes = JasperExportManager.exportReportToPdf(jasperPrint); //设置文件格式 response.setContentType("application/pdf"); response.setHeader("Content-disposition","attachment; filename="+reportModuleName+".pdf"); //设置文件内容大小 response.setContentLength(bytes.length); response.setCharacterEncoding("UTF-8"); //获取输出流 ServletOutputStream ouputStream = response.getOutputStream(); //打印输出流 ouputStream.write(bytes, 0, bytes.length); //刷新输出流 ouputStream.flush(); //关闭输出流 ouputStream.close(); } catch (JRException jre) { System.out.println("JRException:" + jre.getMessage()); jre.printStackTrace(); } }
html 子方法
@SuppressWarnings("deprecation") public void showHTMLPage(HttpServletRequest request, HttpServletResponse response, Map<String, String> parameters, List<?> resultList, String reportModuleName) throws IOException { try { //页面格式编码设置 response.setContentType("text/html;charset=UTF-8"); //定义文件操作(读写)类 PrintWriter out = response.getWriter(); //根据报表文件的物理路径绘制报表文件 File reportFile = new File(request.getRealPath("/report/"+reportModuleName+".jasper")); String reportFilePath = reportFile.getPath(); JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(resultList); JasperPrint jasperPrint; jasperPrint = JasperFillManager.fillReport(reportFilePath, parameters, ds); /**JasperRunManager.runReportToHtmlFile(reportFilePath, parameters, conn); 生成静态HTML页面到*.jsper同目录文件下**/ //JRXxxExporter:这是一系列的文件导出器,他们用于将*.jrprint 文件导出成对应格式的报表文件 //使用JRHtmlExproter导出Html格式, Xls格式的导出器 JRXlsAbstractExport JRHtmlExporter exporter = new JRHtmlExporter(); //图片路径 exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,request.getContextPath()+"\\report\\image\\"); request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE,jasperPrint); //填充导出器的相关参数 exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_WRITER,out); exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN,Boolean.TRUE); //导出 exporter.exportReport(); out.close(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
把报表的模板生成好,放到相应的路径下就OK了。
发表评论
-
测速网站
2016-09-06 18:01 0https://www.webpagetest.org/能 ... -
高并发量网站解决方案
2015-07-10 10:41 1062一个小型的网站,可以 ... -
ubantu自带的tcpdump(抓包工具的使用)
2012-08-29 19:17 9951.在命令下 root@ubantu:~# man tcpd ... -
MyEclipse8.6安装svn(非link方式) .
2012-06-06 18:27 1484此方法经试验可行, ... -
J2EE 领域的一些技术框架结构图
2012-05-10 13:19 1015顶 1 踩 1.Spring 架构图 ... -
Eclipse以及Myeclipse 单步调试
2012-04-11 12:39 13581.在Eclipse中启动Tomcat。 2.在待调试的 ... -
10 个技巧让你的 RESTful Web 服务更加实用
2012-04-10 11:12 732提示:随着RESTful Web services的流行程度不 ... -
关于JSP网页开发中tomcat、myeclipse完全配置
2012-04-06 18:09 2046关于JSP网页开发中tomcat ... -
java.lang.UnsupportedClassVersionError: Bad version number in .class file
2012-02-18 20:16 905后来发现是在中心创建这个工程的时候,使用的JDK是Java5但 ... -
在js文件里引入其他js文件
2012-02-02 21:10 1162第一个js文件(被引入的js文件),文件名one.js,内容如 ... -
● JS中的window.setTimeout()详解
2012-02-01 15:48 1141setTimeout (表达式,延时时间)setInter ... -
转Ext性能优化
2011-12-29 15:41 851前一阶段由于页面上 ... -
解决ext下拉列表全选和去全选功能
2011-12-29 12:50 1214最近在做ext的项目,需求要求处理下拉列表要有全选和去全选的功 ... -
java解压缩包,在linux下,Aix系统下乱码处理方法
2011-12-08 18:28 3587需求:大批量的数据,包含多级目录,目录结构不确定,最后的文件为 ... -
转—Sybase数据库简介
2011-07-27 14:37 688一、Sybase数据库简介 1 ... -
在当前页面直接加载当前月份
2010-11-30 16:31 8101。 js window.onload = function ... -
下载服务器上的文件-纯java处理
2010-07-06 19:05 18719public void download(HttpServle ... -
如何清jboss缓存
2010-07-06 18:50 3860要清除Jboss下的缓存,只要清除以下文件的所有文件就可以了: ... -
Java集合类
2010-05-30 14:34 735集合类说明及区别Colle ... -
string对象
2010-05-25 22:01 753/** * @author fxliu * @vers ...
相关推荐
详细介绍用友UFO报表使用,从新建报表到公式调整,生成报表。
锐浪报表使用技巧锐报表使用技巧 锐浪报表使用技巧_计算机软件及应用_IT/计算机_专业资料。网上相关资料不多,整理一下,大家看看吧。锐浪报表不错就是例子不具体
非常齐全的润乾报表使用方法和开发过程,有助于掌握报表的使用,提升开发效率
用友U8自定义报表使用存储过程时,使用系统的分组和小计、累计、合计
U8自定义报表使用存储过程时,使用系统的分组和小计、累计、合计
润乾报表使用手册.doc
本文档包含润乾报表使用的方法!介绍了润乾报表V4.0的下载网址及注意事项!按照本文档的操作,你就可以轻松学会报表的使用。
水晶报表使用说明和教程,TXT文档教程.
U850自定义报表使用指南,是在用友U8开发自定义报表的好帮手。
visual studio 自带的RDLC报表的使用技巧. 个人建议在做报表的时候尽量用自带的RDLC去代替水晶报表. 稳定性会好很多.
用友手册资料:U9_Web_UFO报表使用指南.pdf
自定义报表使用技巧自定义报表使用技巧总结
在VS .NET 2005中,Microsoft提供了针对这种报表的设计器,并提供了在WinForm和WebForm中使用这种报表的能力。Microsoft将这种报表的后缀定为RDLC,RDL仍然是Report Definition Language的缩写,那么C代表什么呢?C...
水晶报表使用入门,常用的使用
这是关于eclispe(myeclispe)下报表工具birt的使用说明 适合birt初学者
通达OA复杂报表使用手册,版报表中心 集中于 集中于 解决“数据出口 解决“数据出口 解决“数据出口 解决“数据出口 解决“数据出口 (输出) (输出) (输出) ”的问题,提供数据统计、 汇总分析”的问题,提供...
使用帆软提供的报表,可以查看此文档,了解报表中使用的语法规则和方法释义,并学会制作报表。
birt制作报表使用css,对修改birt报表样式非常有用。
很好,很有用,值得一看!学习的好东西,放心下载,值得 下载!!!!!!!!!!!!!!!!!!!!!!!!!
C# 常用整合的资料,NET环境下水晶报表使用总结,水晶报表是一个优秀的报表开发工具,本人在开发通用管理系统的时候,所有报表都使用水晶报表,其简单、易用和强大的功能令笔者倍加喜爱,现将水晶报表使用手记呈现给...