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. 【hdu6121】 Build a tree 简单数学题

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6121 我好像推得挺久的诶..... 题目大意:给你一棵有$n$个点的树,根节点为$0$,对于其余节点 ...

  2. 如何修复“sshd error: could not load host key”

    问题:当我尝试SSH到一台远程服务器时,SSH客户端登陆失败并提示“Connection closed by X.X.X.X”.在SSH服务器那端,我看到这样的错误消息:“sshd error: co ...

  3. java 中几种常用数据结构

    Java中有几种常用的数据结构,主要分为Collection和map两个主要接口(接口只提供方法,并不提供实现),而程序中最终使用的数据结构是继承自这些接口的数据结构类. 一.几个常用类的区别 1.A ...

  4. linux 的yum源

    1.备份 防止以后要用 mkdir /etc/yum.repos.d/backup mv /etc/yum.repos.d/CentOS-*.repo /etc/yum.repos.d/backup ...

  5. jieba分词过程

    jieba分词最重要的就是字典,我们一般用jieba的话是用的它通用的字典,这样在特定的环境中无法分成我们想要的效果,我们需要根据我们自己的生产环境自己添加我们的字典,然后下载jieba源码进行更改, ...

  6. linux下在线升级nodejs

    因现有项目需要用一个截屏node包,此包必须新版本,所以紧急升级下测试环境nodejs,后续再升级线上,小小试了下node在线升级 方案1,使用npm安装n模块,使用n来升级nodejs 首先要知道n ...

  7. Golang 并发Groutine详解

    概述 1.并行和并发 并行(parallel):指在同一时刻,有多条指令在多个处理器上同时执行. 并发(concurrency):指在同一时刻只能有一条指令执行,但多个进程指令被快速的轮换执行,使得在 ...

  8. [转载]Jquery mobiscroll 移动设备(手机)wap日期时间选择插件以及滑动、滚动插件

    Jquery Mobiscroll是一个用于触摸设备(Android phones, iPhone, iPad, Galaxy Tab)的日期和时间选择器jQuery插件.以及各种滑动插件 可以让用户 ...

  9. mariadb(mysql)从库relaylog损坏无法同步的处理方法

    故障说明 晚上备用服务器自动重启,收到报警,备用服务器上的mariadb从库无法去同步主库.启动mariadb后,报如下错误(重点看红色字体)  mariadb_1 | -- :: [Note] Pl ...

  10. [转]AngularJS中$timeout和$interval的用法详解

    本文转自:http://www.cnblogs.com/moli-/p/5827618.html 1. 先将$interval,$timeout,作为参数注入到controller中,例如rds.co ...