ireport直接打印报表,不预览.doc_第1页
ireport直接打印报表,不预览.doc_第2页
ireport直接打印报表,不预览.doc_第3页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

(转)ireport直接打印报表,不预览2011年02月23日 星期三 下午 02:06打印类代码如下:package com.sofn.struts.report.actions;import java.io.File;import java.io.ObjectOutputStream;import java.util.ArrayList;import java.util.List;import java.util.Map;import javax.naming.Context;import javax.naming.InitialContext;import javax.naming.NameNotFoundException;import javax.servlet.ServletOutputStream;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.sql.DataSource;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JasperFillManager;import net.sf.jasperreports.engine.JasperPrint;import net.sf.jasperreports.engine.JasperPrintManager;import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;import org.apache.struts.action.Action;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import com.lowagie.text.ExceptionConverter;import com.sofn.struts.dto.UserInfoDTO;import com.sofn.struts.op.UserInfo;import com.sofn.util.UserSessionOperate;public class ReportViewAction extends Action (org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)throws Exception /已编译文件路径和格式String fp =this.getServlet().getServletContext().getRealPath(/)+ reportjasper+ request.getAttribute(rdoc)+ .jasper;File reportFile = new File(fp);/System.out.println(报表路径!+reportFile);Map parameters = (Map) request.getAttribute(paras);byte bytes = null;List list = new ArrayList();DataSource ds = null;JasperPrint jasperPrint=null;/参数传递UserSessionOperate uso = new UserSessionOperate();String user = uso.getUser(request);UserInfo eidr = new UserInfo();UserInfoDTO eidrdto = null;String deptname = 物流部门;String username = 陈云刚;parameters.put(marker, username);parameters.put(bumen, deptname);/数据库连接try String source = java:comp/env/jdbc/posuse;Context ic = null;if (ic = null)ic = new InitialContext();ds = (DataSource) ic.lookup(source);if (ds = null) System.out.println(Reportview-22222!); catch (NameNotFoundException nfe) nfe.toString(); catch (Exception ne) ne.printStackTrace();/使用数据源if (request.getAttribute(datasource) != null) list = (List) request.getAttribute(reportlist);JRBeanCollectionDataSource jds =new JRBeanCollectionDataSource(list);/使用数据源/使用SQL查询try jasperPrint =JasperFillManager.fillReport(reportFile.getPath(),parameters,ds.getConnection();/填充报表数据生成JasperPrint对象 JasperPrintManager.printReport(jasperPrint, false);/2008-08-25 直接打印,不用预览PDF直接打印true为弹出打印机选择.false为直接打印. catch (JRException jre) /System.out.println(Reportview-JRException88888);jre.printStackTrace(); catch (ExceptionConverter ec) ec.getLocalizedMessage();ec.printStackTrace(); catch (NullPointerException npe) npe.getLocalizedMessage();npe.getMessage();npe.toString();System.err); catch (Exception ee) ee.printStackTrace(); /输出response.setContentType(application/octet-stream);ServletOutputStream ouputStream = response.getOutputStream();ObjectOutputStream oos = new ObjectOutputStream(ouputStream);oos.writeObject(jasperPrint);/将JasperPrint对象写入对象输出流中 oos.flush();oos.close();o

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论