对于jasperreport打印这个功能,遇到了一大堆问题,也只能一点一点解决我:

1.现在我用的是jasperreport.jar是4.6版本。

(1).因为网上查到:6.0以上版本已经不再支持java打印功能,只能支持页面打印。

(2).如过可以用浏览器打印,那这个打印问题已经解决了

(3).我不想再用5.6版本重新测试一遍了,因为官网给的jasperreport-apples.jar例子里面有很多问题,不想在是一遍

2.对于程序的需要,:

(1).最好在webapp(根目录)下新建一个applets(自命名)文件夹

(2).applets文件夹放入jre1.6.exe或以上版本,因为jasperreport-4.5是jre1.6写的

(3).从官网的jasperreport-4.6例子中,找到commons-collections.jar、commons-digester.jar、commons-logging.jar,和自己的log4j.jar、log4j-core.jar,放入applets

3.对于jasperreports-applet-4.6.0.jar,也放入applets,但是等到测试的时候,这个jar包里有很多问题,如果提示这个class找不到,就从jasperreoprt-4.6.jar中粘进去

创建jar包

(1).官网给的例子jasperreport-applets-4.6.jar解压后,复制default.jasperreports.properties、net,新建文件夹,粘进去

(2).将缺少的class从jasperreport-4.6.jar粘到你放的位置对应的位置

(3).ctrl+p命令,将default.jasperreports.properties、net生成一个jasperreport-applets-4.6.jar,放入applets

4.这是我把官网例子改了以后的代码

importnet.sf.jasperreports.engine.JasperPrint;importnet.sf.jasperreports.engine.JasperPrintManager;importnet.sf.jasperreports.engine.util.JRLoader;import javax.swing.*;importjava.io.PrintWriter;importjava.io.StringWriter;importjava.net.URL;/*** Created by 朱星翰 on 2017/9/14.*/

public class JRPrinterApplet extendsjavax.swing.JApplet {privateURL url;privateJasperPrint jasperPrint;publicJRPrinterApplet(){

}public voidinit() {

String strUrl= getParameter("REPORT_URL");if (strUrl != null) {try{

url= newURL(getCodeBase(), strUrl);

}catch(Exception e) {

StringWriter swriter= newStringWriter();

PrintWriter pwriter= newPrintWriter(swriter);

e.printStackTrace(pwriter);

JOptionPane.showMessageDialog(this, swriter.toString());

}

}else{

JOptionPane.showMessageDialog(this, "REPORT_URL:不能为空!");

}

}

@Overridepublic voidstart() {if (url != null) {if (jasperPrint == null) {try{

jasperPrint=(JasperPrint) JRLoader.loadObject(url);

}catch(Exception e) {

StringWriter swriter= newStringWriter();

PrintWriter pwriter= newPrintWriter(swriter);

e.printStackTrace(pwriter);

JOptionPane.showMessageDialog(this, swriter.toString());

}

}if (jasperPrint != null) {final JasperPrint print =jasperPrint;

Thread thread= new Thread(newRunnable()

{public voidrun()

{try{

JasperPrintManager.printReport(print,true);

}catch(Exception e) {

StringWriter swriter= newStringWriter();

PrintWriter pwriter= newPrintWriter(swriter);

e.printStackTrace(pwriter);

JOptionPane.showMessageDialog(null, swriter.toString());

}

}

});

thread.start();

}else{

JOptionPane.showMessageDialog(this, "报表是空的!");

}

}else{

JOptionPane.showMessageDialog(this, "REPORT_URL:不能为空!");

}

}

}

importnet.sf.jasperreports.engine.JasperPrint;importnet.sf.jasperreports.engine.util.JRLoader;import javax.swing.*;importjava.io.PrintWriter;importjava.io.StringWriter;importjava.net.URL;/*** Created by 朱星翰 on 2017/9/14.*/

public class JRViewApplet extendsjavax.swing.JApplet {privateURL url;privateJasperPrint jasperPrint;publicJRViewApplet(){

}public voidinit() {

String strUrl= getParameter("REPORT_URL");if (strUrl != null) {try{

url= newURL(getCodeBase(), strUrl);

}catch(Exception e) {

StringWriter swriter= newStringWriter();

PrintWriter pwriter= newPrintWriter(swriter);

e.printStackTrace(pwriter);

JOptionPane.showMessageDialog(this, swriter.toString());

}

}else{

JOptionPane.showMessageDialog(this, "REPORT_URL:不能为空!");

}

}

@Overridepublic voidstart() {//Add your handling code here:

if (url != null) {try{if (jasperPrint == null) {

jasperPrint=(JasperPrint) JRLoader.loadObject(url);

}if (jasperPrint != null) {

ViewerFrame viewerFrame= new ViewerFrame(this.getAppletContext(), jasperPrint);

viewerFrame.show();

}else{

JOptionPane.showMessageDialog(this, "报表是空的!");

}

}catch(Exception e) {

StringWriter swriter= newStringWriter();

PrintWriter pwriter= newPrintWriter(swriter);

e.printStackTrace(pwriter);

JOptionPane.showMessageDialog(this, swriter.toString());

}

}else{

JOptionPane.showMessageDialog(this, "REPORT_URL:不能为空!");

}

}

}

/** JasperReports - Free Java Reporting Library.

* Copyright (C) 2001 - 2011 Jaspersoft Corporation. All rights reserved.

*http://www.jaspersoft.com*

* Unless you have purchased a commercial license agreement from Jaspersoft,

* the following license terms apply:

*

* This program is part of JasperReports.

*

* JasperReports is free software: you can redistribute it and/or modify

* it under the terms of the GNU Lesser General Public License as published by

* the Free Software Foundation, either version 3 of the License, or

* (at your option) any later version.

*

* JasperReports is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU Lesser General Public License for more details.

*

* You should have received a copy of the GNU Lesser General Public License

* along with JasperReports. If not, see .*/

importjavax.swing.JButton;importjavax.swing.JOptionPane;importnet.sf.jasperreports.engine.JRException;importnet.sf.jasperreports.engine.JasperPrint;importnet.sf.jasperreports.view.JRViewer;/***@authorTeodor Danciu (teodord@users.sourceforge.net)

*@version4.6.0*/

public class JRViewerPlus extendsJRViewer {/*protected JButton btnPlus = new javax.swing.JButton();*/

public JRViewerPlus(JasperPrint jrPrint) throwsJRException {super(jrPrint);

tlbToolBar.remove(btnSave);

tlbToolBar.remove(btnReload);/*btnPlus = new javax.swing.JButton();

btnPlus.setToolTipText("Plus...");

btnPlus.setText("Plus...");

btnPlus.setPreferredSize(new java.awt.Dimension(80, 23));

btnPlus.setMaximumSize(new java.awt.Dimension(80, 23));

btnPlus.setMinimumSize(new java.awt.Dimension(80, 23));

btnPlus.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btnPlusActionPerformed(evt);

}

});

tlbToolBar.add(btnPlus, 0);*/}protected voidsetZooms() {this.zooms = new int[]{33, 66, 100, 133, 166, 200, 233};this.defaultZoomIndex = 2;

}/*protected void btnPlusActionPerformed(java.awt.event.ActionEvent evt) {

JOptionPane.showMessageDialog(this, "I just wanted to let you know that you can extend the JRViewer to customize it.\n The button you have pushed was added this way.");

}*/}

/** JasperReports - Free Java Reporting Library.

* Copyright (C) 2001 - 2011 Jaspersoft Corporation. All rights reserved.

*http://www.jaspersoft.com*

* Unless you have purchased a commercial license agreement from Jaspersoft,

* the following license terms apply:

*

* This program is part of JasperReports.

*

* JasperReports is free software: you can redistribute it and/or modify

* it under the terms of the GNU Lesser General Public License as published by

* the Free Software Foundation, either version 3 of the License, or

* (at your option) any later version.

*

* JasperReports is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU Lesser General Public License for more details.

*

* You should have received a copy of the GNU Lesser General Public License

* along with JasperReports. If not, see .*/

importnet.sf.jasperreports.engine.JRException;importnet.sf.jasperreports.engine.JasperPrint;importnet.sf.jasperreports.view.JRViewer;/***@authorTeodor Danciu (teodord@users.sourceforge.net)

*@version4.6.0*/

public class JRViewerSimple extendsJRViewer {/****/

public JRViewerSimple(JasperPrint jrPrint) throwsJRException {super(jrPrint);

tlbToolBar.remove(btnSave);

tlbToolBar.remove(btnReload);

}

}

/** JasperReports - Free Java Reporting Library.

* Copyright (C) 2001 - 2011 Jaspersoft Corporation. All rights reserved.

*http://www.jaspersoft.com*

* Unless you have purchased a commercial license agreement from Jaspersoft,

* the following license terms apply:

*

* This program is part of JasperReports.

*

* JasperReports is free software: you can redistribute it and/or modify

* it under the terms of the GNU Lesser General Public License as published by

* the Free Software Foundation, either version 3 of the License, or

* (at your option) any later version.

*

* JasperReports is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU Lesser General Public License for more details.

*

* You should have received a copy of the GNU Lesser General Public License

* along with JasperReports. If not, see .*/

importjava.applet.AppletContext;importjava.awt.BorderLayout;importjava.net.MalformedURLException;importjava.net.URL;importjavax.swing.JOptionPane;importnet.sf.jasperreports.engine.JRException;importnet.sf.jasperreports.engine.JRPrintHyperlink;importnet.sf.jasperreports.engine.JasperPrint;importnet.sf.jasperreports.view.JRHyperlinkListener;/***@authorTeodor Danciu (teodord@users.sourceforge.net)

*@version4.6.0*/

public class ViewerFrame extends javax.swing.JFrame implementsJRHyperlinkListener {privateAppletContext appletContext;public ViewerFrame(AppletContext appletContext, JasperPrint jasperPrint) throwsJRException {

initComponents();this.appletContext =appletContext;

JRViewerPlus viewer= newJRViewerPlus(jasperPrint);

viewer.addHyperlinkListener(this);this.pnlMain.add(viewer, BorderLayout.CENTER);

}public voidgotoHyperlink(JRPrintHyperlink hyperlink) {switch(hyperlink.getHyperlinkTypeValue()) {caseREFERENCE : {try{this.appletContext.showDocument(new URL(hyperlink.getHyperlinkReference()), "_blank");

}catch(MalformedURLException e) {

JOptionPane.showMessageDialog(this, e.getMessage());

}break;

}caseLOCAL_ANCHOR :caseLOCAL_PAGE : {break;

}caseREMOTE_ANCHOR :caseREMOTE_PAGE : {

JOptionPane.showMessageDialog(this, "Implement your own JRHyperlinkListener to manage this type of event.");break;

}caseNONE :default: {break;

}

}

}/**This method is called from within the constructor to

* initialize the form.

* WARNING: Do NOT modify this code. The content of this method is

* always regenerated by the Form Editor.*/

private void initComponents() {//GEN-BEGIN:initComponents

pnlMain = newjavax.swing.JPanel();

setTitle("预览");

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

pnlMain.setLayout(newjava.awt.BorderLayout());

getContentPane().add(pnlMain, java.awt.BorderLayout.CENTER);

pack();

java.awt.Dimension screenSize=java.awt.Toolkit.getDefaultToolkit().getScreenSize();int width=1000;int height=800;

setSize(newjava.awt.Dimension(width, height));

setLocation((screenSize.width-width)/2,(screenSize.height-height)/2);

}//GEN-END:initComponents//Variables declaration - do not modify//GEN-BEGIN:variables

privatejavax.swing.JPanel pnlMain;//End of variables declaration//GEN-END:variables

}

(1).把这些代码放入src下,生成class代码

(2).将class生成jar,我命名print.jar

(3).jar -cvf print.jar *.class  (生成jar包),放入applets

5.签名

1.创建一个证书

keytool -genkey -validity 1800 -keystore applet.store -alias applet

2.导出证书文件

keytool -export -keystore applet.store -alias applet -file applet.cer

3.对jar包进行签名

jarsigner -keystore applet.store jasperreports-applet-4.6.0.jar applet

jarsigner -keystore applet.store print.jar applet (注意:必须签名这个jar包,要不然打印报错)

6.页面,自己处理了很多js,

是否安装安全证书?

functionis_ie(str){if ((navigator.userAgent.indexOf('MSIE') >= 0 && navigator.userAgent.indexOf('Opera') < 0)||(navigator.userAgent.indexOf("Trident") > -1 && navigator.userAgent.indexOf("rv") > -1)){var archive='print.jar,jasperreports-applet-4.6.0.jar,commons-logging-1.1.1.jar,commons-collections-2.1.1.jar,commons-digester-2.1.jar';var REPORT_URL='${ctx}/jasper/all_printJasper?';var codebase='${ctx}/applets'

var file='${ctx}/applets/jre-6u45-windows-i586.exe';var scriptable=false

var type='application/x-java-applet;version=1.6.0';

$.each(args,function(key,value){

REPORT_URL+=key+"="+value+"&";

});

REPORT_URL=change(REPORT_URL);

REPORT_URL=encodeURI(REPORT_URL);var write='正在处理'+(str=='JRPrinterApplet'?'打印':'预览')+'...' +

'' +

'' +

'' +

'' +

'' +

'' +

'' +

'' +

'' +

'' +

'' +

'' +

''document.write(write);

}else{

alert('预览打印仅支持ie浏览器')

}

}

最后,终于完成了,总之,觉的jasperreport-applets-4.6官网给的好多错误地方,只有慢慢去找问题

jasperprint java_关于jasperreport对应java打印机的解决方案相关推荐

  1. saas java框架_XMReport-提供web项目Java套打解决方案

    简介 XMReport是国内首款支持在线编辑,维护的控件式报表产品.XMReport报表产品分为设计器与引擎两个部分,其中报表设计器是完全基于HTML5技术,提供优秀跨平台的支持,用户无需安装客户端或 ...

  2. java幂等性的解决方案

    java幂等性的解决方案 参考文章: (1)java幂等性的解决方案 (2)https://www.cnblogs.com/xinruyi/p/11441818.html (3)https://www ...

  3. Java Scoket之java.io.EOFException解决方案

    Java Scoket之java.io.EOFException解决方案 参考文章: (1)Java Scoket之java.io.EOFException解决方案 (2)https://www.cn ...

  4. Hive Error : Java heap space 解决方案

    Hive Error : Java heap space 解决方案 参考文章: (1)Hive Error : Java heap space 解决方案 (2)https://www.cnblogs. ...

  5. 【java】 java 高并发解决方案和高负载优化方法

    [java] java 高并发解决方案和高负载优化方法 参考文章: (1)[java] java 高并发解决方案和高负载优化方法 (2)https://www.cnblogs.com/lonelywo ...

  6. Java 图片处理解决方案:ImageMagick 快速入门教程

    Java 图片处理解决方案:ImageMagick 快速入门教程 参考文章: (1)Java 图片处理解决方案:ImageMagick 快速入门教程 (2)https://www.cnblogs.co ...

  7. AndroidRuntime java.lang.AbstractMethodError解决方案

    AndroidRuntime: java.lang.AbstractMethodError解决方案 背景介绍 今天同事尝试编译apk的release版本,编译成功,但是运行时,却爆出这个运行时异常,导 ...

  8. java word 乱码_(word)Java乱码问题解决方案.doc

    (word)Java乱码问题解决方案 Java乱码问题解决方案 Java乱码问题一直是困扰初学者的一个难题,下面就根据笔者的经验来给大家一个解决方案.我写了一个Demo的web应用,解决了乱码问题,点 ...

  9. jasperreport java数据,报表,IReport+JasperReport进行Java报表开发。

    一  相关基础知识 1.关于JasperReport和iReport Jasperreport是一个报表制作程序,用户需要按照它制定的规则编写一个XML文件,然后得到用户需要输出的格式文件.它支持输出 ...

最新文章

  1. Git常见疑难解答集锦
  2. java system_深入分析java中的System
  3. .net ajax批量删除,asp.net 全部选中与取消操作,选中后的删除(ajax)实现无刷新效果...
  4. 准备重新回归信息安全产业
  5. 神经网络告诉我,谁是世界上最「美」的人?
  6. linux-basic(9)文件与文件系统的压缩与打包
  7. 【Jmeter篇】jmeter Ant Jenkins接口自动化测试集成之半路逆转(二)
  8. 12.2日,第二次团队冲刺开始
  9. 让系统自动登录的方法
  10. 洛谷——P1089 [NOIP2004 提高组] 津津的储蓄计划
  11. python画折线图-python如何画折线图
  12. lua能在stm32arm上运行吗_IOS App能在Mac运行!苹果这黑科技能撼动微软吗?
  13. 关于React Native init 项目时候速度太慢的解决方法
  14. cocos判断鼠标点击_面试官:你可以用纯 CSS 判断鼠标进入的方向吗?
  15. 电工模拟接线软件 app_超全的电工接线方法口诀
  16. 使用 wizNote 作为 Metaweblog 客户端 在博客园发布博客
  17. Fastjson实用工具类,List转JSONString,List转JSONArray,JSONArray转List,JSONArray转ArrayList,JSONObject转HashMap
  18. 数学公式编辑器mathtype安装包免费版下载
  19. ThreadPoolExecutor参数解析
  20. 联想计算机怎么添加打印机,电脑和联想打印机连接不上怎么办啊

热门文章

  1. 【语音去噪】基于matlab小波硬阈值语音降噪【含Matlab源码 532期】
  2. 黄金跳槽期到了,一个优秀程序员的简历应该怎么写
  3. live555 rtp 封装h264h265 数据
  4. 黑客突破物理隔离的8种方法
  5. html搜索栏背景透明,Win10秘籍:让Cortana搜索框“透明”给你看
  6. 职称计算机考试题库word2003,2016职称计算机考试Word2003练习试题
  7. 12.16 Daily Scrum
  8. python 解析pb文件_Tensorflow:从图形文件(.pb文件)中获取预测
  9. 有线电视与计算机网都是光缆吗,有线电视网络技术浅谈
  10. 画个板子玩玩最便宜的Arduino,Atmega8A 的使用