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. PCA降维

    http://blog.csdn.net/a784763307/article/details/17289317 这篇比较棒 openCV版 void PrintMatrix(CvMat *Matri ...

  2. xml bug之cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration...

    1.今天重装了一下MyEclipse7.5,打开原来的Flex项目,又报了以下两个错误,之前解决过,但不想又出现,于是把它的解决方法贴出来,做个备忘! 错误信息为 错误信息 写道 cvc-comple ...

  3. Dynamically loading an external JavaScript or CSS file

    原文:   Dynamically loading an external JavaScript or CSS file 通过javascript动态加载css文件和javascript文件,主要是通 ...

  4. HTML实现跳转到页面指定位置

    <a href="#page1">跳转到页面1</a> <a href="#page2">跳转到页面2</a> ...

  5. ajax提交表单 验证

    function submitKH(mobileInputId,nameInputId) { var mobileInputSelector ='#'+ mobileInputId; var pass ...

  6. 读书笔记 effective c++ Item 34 区分接口继承和实现继承

    看上去最为简单的(public)继承的概念由两个单独部分组成:函数接口的继承和函数模板继承.这两种继承之间的区别同本书介绍部分讨论的函数声明和函数定义之间的区别完全对应. 1. 类函数的三种实现 作为 ...

  7. htm5

    htm5在html4.0. xhtm1.0的基础上增加了音频.视频.拖拽等功能,不过,htmL5,还在完善中,不过大部分浏览器都已经支持了部分功能. 兼容性: 最新版本的 Safari.Chrome. ...

  8. nginx 完成缓存清除 以及升级包的自动升级

    #!/bin/bash function cache(){ for i in `curl xxx.fe.xxx.cn/uplist.txt`;do url=`echo $i|awk -F"# ...

  9. usb-cam(1)安装

    http://www.liuxiao.org/2015/10/ros-%E5%AE%89%E8%A3%85-usb-camera-%E9%A9%B1%E5%8A%A8%E5%B9%B6%E8%B0%8 ...

  10. EventBus简单封装

    前言 以前每个页面与每个页面业务逻辑传递让你不知所措,一个又一个接口回调,让你晕头转向,一个又一个参数让你混乱不堪.EventBus一个耦合度低的让你害怕的框架. 什么是EventBus EventB ...