1 . 问题概述


当报表运算完成时,客户端经常需要调用润乾自带的runqianReport4Applet.jar来完成打印操作, 然而数据量比较大的时候,会导致无法加载完成,直至applet内存溢出



为了解决这个问题我们提出了打印分页传输方案.

2 . 案例

南通烟草局

3. 解决思路

1、打印窗口显示时,先向服务器申请第一页,并显示第一页。

2、在预览窗口按下一页或最后页按钮时,如果此页还没有从服务器取过来,那么先将之取过来并显示。

3、在打印窗口中依然可以改变页面设置、分栏数、缩放打印等,让服务器重新分页,并传第一页来显示。

4、在按打印按钮时,弹出一个新窗口,此窗口中可以选择打印机、设置要打印的页、显示打印进度、停止打印或退出。



 为了避免内存溢出,采取每5页为一个打印单位发送给打印机,这5页打印完后就将从内存中清除。以此类推.

4. 配置说明

实现:

1、在web.xml中配置后台分页传输的服务,如下
<servlet>


<servlet-name>com.runqian.report4.view.PagedPrint</servlet-name>

<servlet-class>com.runqian.report4.view.PagedPrint</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>com.runqian.report4.view.PagedPrint</servlet-name>

<url-pattern>/servlet/pagedPrintServer</url-pattern>

</servlet-mapping>

2、htmlTag中增加一个属性
serverPagedPrint="yes"


applet打印时是否采用服务器分页后再按页传输的方式,值为yes或no。一般大数据量的报表采用此方式

5. 程序说明

package com.runqian.report4.view;

import com.runqian.report4.cache.PagerCache;

import com.runqian.report4.cache.ReportCache;

import com.runqian.report4.cache.ReportEntry;

import com.runqian.report4.control.PageRequest;

import com.runqian.report4.control.PageResponse;

import com.runqian.report4.usermodel.Context;

import com.runqian.report4.usermodel.DataSetMetaData;

import com.runqian.report4.usermodel.IReport;

import com.runqian.report4.usermodel.PagerInfo;

import com.runqian.report4.usermodel.PrintSetup;

import com.runqian.report4.util.ReportParser;

import com.runqian.report4.util.ReportUtils2;

import java.awt.print.PageFormat;

import java.awt.print.Paper;

import java.io.IOException;

import java.io.InputStream;

import java.io.ObjectInputStream;

import java.io.ObjectOutputStream;

import java.io.OutputStream;

import javax.servlet.GenericServlet;

import javax.servlet.ServletException;

import javax.servlet.ServletInputStream;

import javax.servlet.ServletOutputStream;

import javax.servlet.ServletRequest;

import javax.servlet.ServletResponse;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

public
class PagedPrint
extends HttpServlet

{

private PageFormat _$1(double
paramDouble, PageFormat paramPageFormat)

{

PageFormat localPageFormat = new PageFormat();

Paper localPaper1 = new Paper();

Paper localPaper2 = paramPageFormat.getPaper();

localPaper1.setSize(localPaper2.getWidth() * paramDouble, localPaper2.getHeight() * paramDouble);

double d1 = localPaper2.getImageableX() * paramDouble;

double d2 = localPaper2.getImageableY() * paramDouble;

double d3 = localPaper2.getImageableWidth() * paramDouble;

double d4 = localPaper2.getImageableHeight() * paramDouble;

localPaper1.setImageableArea(d1, d2, d3, d4);

localPageFormat.setPaper(localPaper1);

localPageFormat.setOrientation(paramPageFormat.getOrientation());

return localPageFormat;

}

private
void _$1(IReport paramIReport) {

if (paramIReport ==
null)
return;

try {

paramIReport.getDataSetMetaData().clear();

return;

}

catch (Throwable localThrowable)

{

}

}

public
void service(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)

throws ServletException, IOException

{

Object localObject3;

ServletInputStream localServletInputStream = null;

ServletOutputStream localServletOutputStream = null;

ObjectOutputStream localObjectOutputStream = null;

PageResponse localPageResponse = new PageResponse();

try {

try { IReport localIReport;

PageFormat localPageFormat1;

PageFormat localPageFormat2;

PagerInfo localPagerInfo;

int i;

Object localObject4;

int j;

int k;

localObject3 = getServletContext();

localServletInputStream = paramHttpServletRequest.getInputStream();

ObjectInputStream localObjectInputStream = new ObjectInputStream(localServletInputStream);

localServletOutputStream = paramHttpServletResponse.getOutputStream();

localObjectOutputStream = new ObjectOutputStream(localServletOutputStream);

PageRequest localPageRequest = (PageRequest)localObjectInputStream.readObject();

Context localContext = new Context();

ReportEntry localReportEntry = ReportUtils2.getReportEntry(localPageRequest.fileName, localPageRequest.srcType,
paramHttpServletRequest, localContext);

ReportCache localReportCache = null;

if ((

localReportCache = localReportEntry.getReportCache(localPageRequest.cachedId)) ==
null)

{

if (localPageRequest.reportParamsId
!= null)

ReportUtils2.putParamMacro2Context(localReportEntry.getReportDefine(), localPageRequest.reportParamsId,
localContext, paramHttpServletRequest);

localReportCache = localReportEntry.getReportCache(localContext, -1L);

}

localPageResponse.cachedId = localReportCache.getId();

PrintSetup localPrintSetup = (

localIReport = localReportCache.getReport())

.getPrintSetup();

switch (localPageRequest.action)

{

case 1:

localPagerInfo = new PagerInfo(localPrintSetup);

localPageFormat1 = localPrintSetup.getPageFormat();

if ((

i = localPrintSetup.getZoomMode()) ==

1) {

localPageFormat2 = localPageFormat1;

localPageResponse.shrinkScale = 1.0D;

}

else
if (i == 5) {

localPageResponse.shrinkScale = (localPrintSetup.getZoomScale() / 100);

localPageFormat2 = _$1(1.0D / localPageResponse.shrinkScale, localPageFormat1);

localPagerInfo.setPageFormat(localPageFormat2);

}

else {

localObject4 = new ReportParser(localIReport);

if (i == 2) {

j = ((ReportParser)localObject4).getReportWidth() + 2;

localPageResponse.shrinkScale = (localPageFormat1.getImageableWidth() / j);

}

else
if (i == 3) {

j = ((ReportParser)localObject4).getReportHeight() + 2;

localPageResponse.shrinkScale = (localPageFormat1.getImageableHeight() / j);

}

localPageFormat2 = _$1(1.0D / localPageResponse.shrinkScale, localPageFormat1);

localPagerInfo.setPageFormat(localPageFormat2);

}

j = (

(PagerCache) (localObject4 = localReportCache.getPagerCache(localPagerInfo)))

.getPageCount();

k = 1;

if (localPrintSetup.getPagerStyle() == 1) {

k = localPrintSetup.getLayoutRowNum() * localPrintSetup.getLayoutColNum();

j = j / k + ((j % k == 0) ? 0 : 1);

}

localPageResponse.align = localPrintSetup.getHAlign();

localPageResponse.vAlign = localPrintSetup.getVAlign();

localPageResponse.count = j;

localPageResponse.pages = k;

localPageResponse.page = ((PagerCache)localObject4).getPage(1);

_$1(localPageResponse.page);

localPageResponse.pagerInfo =
new PagerInfo(localPrintSetup);

localPageResponse.pagesId = ((PagerCache)localObject4).getId();

localPageResponse.shrink = (byte)
i;

break;

case 3:

localPageFormat1 = (

localPagerInfo = localPageRequest.pagerInfo)

.getPageFormat();

if ((

i = localPageRequest.shrink) ==

1) {

localPageFormat2 = localPageFormat1;

localPageResponse.shrinkScale = 1.0D;

}

else
if (i == 5) {

localPageResponse.shrinkScale = (localPrintSetup.getZoomScale() / 100);

localPageFormat2 = _$1(1.0D / localPageResponse.shrinkScale, localPageFormat1);

localPagerInfo.setPageFormat(localPageFormat2);

}

else {

int l;

ReportParser localReportParser = new ReportParser(localIReport);

if (i == 2) {

l = localReportParser.getReportWidth() + 2;

localPageResponse.shrinkScale = (localPageFormat1.getImageableWidth() / l);

}

else
if (i == 3) {

l = localReportParser.getReportHeight() + 2;

localPageResponse.shrinkScale = (localPageFormat1.getImageableHeight() / l);

}

localPageFormat2 = _$1(1.0D / localPageResponse.shrinkScale, localPageFormat1);

localPagerInfo.setPageFormat(localPageFormat2);

}

j = (

(PagerCache) (localObject4 = localReportCache.getPagerCache(localPagerInfo)))

.getPageCount();

k = 1;

if (localPrintSetup.getPagerStyle() == 1) {

k = localPrintSetup.getLayoutRowNum() * localPrintSetup.getLayoutColNum();

j = j / k + ((j % k == 0) ? 0 : 1);

}

localPageResponse.count = j;

localPageResponse.pages = k;

localPageResponse.page = ((PagerCache)localObject4).getPage(1);

_$1(localPageResponse.page);

localPageResponse.pagesId = ((PagerCache)localObject4).getId();

break;

case 2:

if ((

localObject4 = localReportCache.getPagerCache(localPageRequest.pagesId)) ==
null)

{

localObject4 = localReportCache.getPagerCache(localPageRequest.pagerInfo);

}

localPageResponse.pagesId = ((PagerCache)localObject4).getId();

if (localPageRequest.pageNo
> ((PagerCache)localObject4).getPageCount()) localPageResponse.page =
null;

else localPageResponse.page
= ((PagerCache)localObject4).getPage(localPageRequest.pageNo);

_$1(localPageResponse.page);

}

}

catch (Throwable localThrowable) {

(

(Throwable) (localObject3 = localThrowable))

.printStackTrace();

localPageResponse.errMsg = ((Throwable)localObject3).getMessage();

if (localPageResponse.errMsg.length()
!= 0) localPageResponse.errMsg =
"error";

}

return;

}

finally

{

try

{

if (localObjectOutputStream ==
null) localObjectOutputStream.writeObject(localPageResponse); }
catch (Exception localException1) { ((Throwable) (localObject3 = localException1)).printStackTrace(); }

if (localServletInputStream !=
null)
try { localServletInputStream.close(); }
catch (Exception localException2) { }

if (localServletOutputStream !=
null) localServletOutputStream.close();

}

}

}

大数据量报表APPLET打印分页传输方案的更多相关文章

  1. MYSQL的大数据量情况下的分页查询优化

    最近做的项目需要实现一个分页查询功能,自己先看了别人写的方法: <!-- 查询 --> <select id="queryMonitorFolder" param ...

  2. 关于MySQL中查询大数据量的情况下分页limit的性能优化

    https://blog.csdn.net/weixin_37848710/article/details/80772725

  3. 大数据量下,分页的解决办法,bubuko.com分享,快乐人生

    大数据量,比如10万以上的数据,数据库在5G以上,单表5G以上等.大数据分页时需要考虑的问题更多. 比如信息表,单表数据100W以上. 分页如果在1秒以上,在页面上的体验将是很糟糕的. 优化思路: 1 ...

  4. MySQL大数据量快速分页实现(转载)

    在mysql中如果是小数据量分页我们直接使用limit x,y即可,但是如果千万数据使用这样你无法正常使用分页功能了,那么大数据量要如何构造sql查询分页呢?     般刚开始学SQL语句的时候,会这 ...

  5. 采用Kettle分页处理大数据量抽取任务

    作者:Grey 原文地址: http://greyzeng.com/2016/10/31/big-data-etl/ 需求: 将Oracle数据库中某张表历史数据导入MySQL的一张表里面. 源表(O ...

  6. 【转载】大数据量传输时配置WCF的注意事项

    WCF传输数据量的能力受到许多因素的制约,如果程序中出现因需要传输的数据量较大而导致调用WCF服务失败的问题,应注意以下配置: 1.MaxReceivedMessageSize:获取或设置配置了此绑定 ...

  7. 解决WCF大数据量传输 ,System.Net.Sockets.SocketException: 远程主机强迫关闭了一个现有的连接

    开发中所用的数据需要通过WCF进行数据传输,结果就遇到了WCF大量传输问题 也就是提示System.Net.Sockets.SocketException: 远程主机强迫关闭了一个现有的连接 网上解决 ...

  8. WCF大数据量传输配置

    WCF传输数据量的能力受到许多因素的制约,如果程序中出现因需要传输的数据量较大而导致调用WCF服务失败的问题,应注意以下配置: 1.MaxReceivedMessageSize:获取或设置配置了此绑定 ...

  9. WCF大数据量传输解决方案

    文章内容列表:1. 场景:2. 解决方案3. WCF契约与服务实现设计静态图4. WCF契约与服务实现设计详细说明6. 服务端启动服务代码:7. 客户端代码8.   WCF大数据量传输解决方案源码下载 ...

随机推荐

  1. aspectj

    http://stackoverflow.com/questions/25209339/spring-aspectj-weaving-for-java-8-using-aspectj-maven-pl ...

  2. Matlab 基础

    命令行(Command Line) 1. help  格式:help  命令 2. cd 配合 Tab 使用 pwd: print current working directory,打印当前工作路径 ...

  3. python3 判断大小端的一种方法

    这里用到了array.array('H', [1])来测试大小端,[1]可以转化为十六进制的0x0001,占两位,00位高位, 01位低位,通过第一位就可以判断大小端. 如果是小端,则转化为bytes ...

  4. ActiveMQ学习--002--Topic消息例子程序

    一.非持久的Topic消息示例 注意 此种方式消费者只能接收到 消费者启动之后,发送者发送的消息. 发送者 package com.lhy.mq.helloworld; import java.uti ...

  5. python:rs, ws, es = select.select(inputs, [], []) --报错error 10022

    昨晚折腾的1个多钟,直到3点多才睡,感觉自己也是热爱代码了,敲3个多钟一点也不累(其实是为了凌晨6点起来抢票回家了^_^) 练习python中select进行异步通信-防止socket.recv方法阻 ...

  6. Spring Boot 不使用默认的 parent,改用自己的项目的 parent

    在初学spring boot时,官方示例中,都是让我们继承一个spring的 spring-boot-starter-parent 这个parent: <parent> <group ...

  7. Linux内核源码目录

    linux和Android的Makefile和android.mk Uboot流程分析(未编辑完) Kernel的IIC驱动分析(未编辑完)

  8. c#调用本地命令并截取Output

    demo1: /// <summary> /// /// </summary> /// <param name="str"></param ...

  9. 【JavaScript 从零开始】 数字 文本 包装对象

    JavaScript中的算术运算 JavaScript 还自称更加复杂的算术运算,这些复杂的运算通过作为Math对象的属性定义的函数和常量来实现: Math.pow(2,53) //=>9007 ...

  10. 线程7--GCD的基本使用

    子线程执行延时操作,执行完成后返回主线程更新界面 dispatch_queue_t queue=dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DE ...