public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { //*String username = request.getParameter("username"); SQLConn sqlConn = new SQLConn(); try { Connection conn = sqlConn.getConnection1(); String root_path = this.getServletContext().getRealPath(""); String reportFilePath = root_path + "\\WEB-INF\\classes\\com\\ztesoft\\bidding\\contract\\jspreport\\javaBean.jasper "; File reportFile1 = new File(reportFilePath); if (!reportFile1.exists()) throw new JRRuntimeException( "没找到文件路径"); JasperReport jasperReport1 = (JasperReport) JRLoader .loadObject(reportFile1.getPath()); //Map parameters = new HashMap(); //parameters.put("id", 1); //-------数据传输------------- List<testVo> data = new ArrayList<testVo>(); testVo TestVo = new testVo(); List<testVo> list = new ArrayList<testVo>(); try { Statement stmt = conn.createStatement(); ResultSet rslt = stmt .executeQuery("select * from PARTNER where partner_id = 2843"); while (rslt.next()) { testVo obj = new testVo(); obj.setContactMan(rslt.getString("CONTACT_MAN")); obj.setContactTel(rslt.getString("contact_Tel")); obj.setBank(rslt.getString("bank")); obj.setAccount(rslt.getString("account")); list.add(obj); } for (int i = 0; i < list.size(); i++) { TestVo.setContactMan(list.get(i).getContactMan()); TestVo.setContactTel(list.get(i).getContactTel()); TestVo.setBank(list.get(i).getBank()); TestVo.setAccount(list.get(i).getAccount()); } //假数据 //数量 budget_amount 单价 price TestVo.setBudgetAmount("10"); TestVo.setPrice("9300.000"); //--商品信息 名称 name 商品型号material_type TestVo.setName("联想电脑XM300"); TestVo.setMaterialType("1颗2.40GHz四核XEON处理器,2GB内存"); // 交货期 2交货地点 联系人 } catch (SQLException e) { e.printStackTrace(); } data.add(TestVo); JRDataSource dataSource = new JRBeanCollectionDataSource(data); //-------数据传输------------------- JasperPrint jasperPrint1 = JasperFillManager.fillReport( jasperReport1, null, dataSource); JRExporter exporter = null; exporter = new JRRtfExporter(); List reportlist = (List) new java.util.ArrayList(); reportlist.add(jasperPrint1); System.out.println(reportlist.size() + "list"); byte[] bytes; ByteArrayOutputStream baos = new ByteArrayOutputStream(); exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, reportlist); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos); //qijia exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint1); //exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out); exporter.exportReport(); // exporter.exportReportToStream(); bytes = baos.toByteArray(); // System.out.println(bytes+"bytes"); if (bytes != null && bytes.length > 0) { System.out.println(bytes+"bytes"); try { //response.reset(); response.setContentType("application/ms_word"); response.setHeader("Content-disposition", "attachment; filename=yourReport.doc"); response.setContentLength(bytes.length); ServletOutputStream ouputStream = response .getOutputStream(); ouputStream.write(bytes, 0, bytes.length); ouputStream.flush(); ouputStream.close(); // response.reset(); } catch (Exception ex) { ex.printStackTrace(); } finally { conn.close(); } } } catch (SQLException e1) { e1.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
详细解决方案
java调ireport-(poi源输出word)(2次试验)
热度:146 发布时间:2016-05-05 07:46:54.0
相关解决方案
- java 乱码 汉字是 ? 如何转换成汉字
- java web 登录次数限制,该如何解决
- java 工商银行网银支付 B2B的 都亟需什么,需要注意什么
- Java Applet程序从JDK6升级到7时遇到的有关问题
- java web 视频相干
- 请教一个关于链接后缀的有关问题(java web 应用)
- java 系统单点登录解决方案
- java.lang.NumberFormatException: For input string: "id"该如何处理
- java.lang.NoSuchMethodException: setId([Ljava.lang.String;)解决方法
- java 获取客户端IP解决办法
- JAVA 后台怎么获得前台页面FCKedit编辑器中的内容以及内容的样式
- java 正则化匹配有关问题
- java web 受阻
- java.lang.IllegalStateException: No output folder,该怎么解决
- java.lang.NoSuchMethodError: org.springframework.util.ReflectionUtils.makeAccess,该如何解决
- java 乱码有关问题 急求大神
- java EE错误如何解决阿,都是过了,没有能解决的!
- java 工程打包有关问题 多谢各位大神!多谢
- JAVA WEB导航条,该怎么处理
- java.sql.SQLException: Access denied for user 'root'@'localhost' (using password,该如何处理
- java 中Node 有关问题
- 关于 java 引述传递和值传递,你的知否
- 吐了,java Timer 终止不了。
- Java Web 学习中有关问题,请高手指教
- java web中的url地址小疑点。
- java web开发解决办法
- java.lang.NullPointerException解决方法
- 关于 java cast 有关问题,你明白不
- java ftp 下传和上载乱码有关问题
- java web项目上的一些文件