Struts2 + JasperReport Application 2: jasperReport Web Forms Printing

Be jasperReport design document and compile files on webRoot the following jasper folder below.

public class Person {
        private String person_Id;

        private String person_name;

        private String person_age;

        private String person_address;
public class PersonService {
        public List<Person> getAllPerson() {
                List<Person> perList = new ArrayList<Person>();
                perList.add(new Person("101", " Klein  ", "22", " Hubei  "));
                perList.add(new Person("102", " Smith, John  ", "21", " Hunan  "));
                perList.add(new Person("103", " Paul Lee  ", "23", " Jiangsu  "));
                perList.add(new Person("104", " Wangwu  ", "22", " Shanghai  "));
                return perList;

Construction of our applet is as follows:

public class JRPrinterApplet extends javax.swing.JApplet {
        private URL url = null;
        public void init() {
                String strUrl = getParameter("REPORT_URL");
                if (strUrl != null) {
                        try {
                                url = new URL(getCodeBase(), strUrl);//  From the HTML parameters in a report URL
                                // System.out.println("url=" + url.toURI());// If the servlet path
                        } catch (Exception e) {
                                StringWriter swriter = new StringWriter();
                                PrintWriter pwriter = new PrintWriter(swriter);
                                JOptionPane.showMessageDialog(this, swriter.toString());
                } else {
                        JOptionPane.showMessageDialog(this, "Source URL not specified");
        public void start() {
                if (url != null) {
                        try {
                                Object obj = JRLoader.loadObject(url);//  Send an object request, obtain JasperPrint object
                                JasperPrintManager.printReport((JasperPrint) obj, true);//  Call the method to print the JasperPrint object
                        } catch (Exception e) {

Structure of our action is as follows:

public class JRPrintAction extends ActionSupport {
        public String execute() throws Exception {
                File reportFile = new File(ServletActionContext.getRequest()
                Map<String, String> parameters = new HashMap<String, String>();
                parameters.put("year", "2009");
                parameters.put("unit_mc", " Wuhan XX technology co., Ltd.  ");
                List<Person> personList = new PersonService().getAllPerson();
                JasperPrint jasperPrint = null;
                JasperReport jasperReport = (JasperReport) JRLoader
                jasperPrint = JasperFillManager.fillReport(jasperReport, parameters,
                                new JRBeanCollectionDataSource(personList));
                }catch (Exception e) {
                        throw e;
                if(null != jasperPrint){
                        HttpServletResponse response = ServletActionContext.getResponse();
                        ServletOutputStream ouputStream = response.getOutputStream();
                        ObjectOutputStream oos = new ObjectOutputStream(ouputStream);
                return null;

struts.xml configuration is as follows:

<action name="jrPrint"
                        <result name="success">/index.jsp</result>

web.xml configuration is as follows:


Be JRPrinterApplet compile files on webRoot the following applet the following folder

Page call is as follows:

<input type="button" value=" Print  " name="button1">

        function print(){
                var url = "jrPrint.action";
                document.write('<APPLET CODE = "JRPrinterApplet.class" CODEBASE = "applets" ARCHIVE = "jasperreports-3.5.2-applet.jar,commons-logging-1.0.2.jar,commons-collections-2.1.jar" WIDTH = "0" HEIGHT = "0">');
                document.write('<PARAM NAME = "type" VALUE="application/x-java-applet;version=1.2.2">');
                document.write('<PARAM NAME = "scriptable" VALUE="false">');
                document.write('<PARAM NAME = "REPORT_URL" VALUE ="'+url+'">');
分类:Java 时间:2010-03-29 人气:460
blog comments powered by Disqus


  • Classic String Object into several forms of [transfer] 2010-10-25

    Classic String Object into several forms of [transfer] Java project in the actual development and applications, often need to use the String object into this basic function. This method will be used to convert a summary. Commonly used method Object #

  • Extend JavaScript's String Object 2010-08-17

    Extend JavaScript's String object methods: 1. ReplaceAll method String.prototype.replaceAll = function(regStr, replaceStr) { var reg = new RegExp(regStr, "gm"); return this.replace(reg, replaceStr); } 2. Trim method String.prototype.trim = funct

  • Please do not take the "String s = new String (" xyz "); created a number of String instances" to the interview now 2010-09-29

    This quote is used to restore high-level language virtual machines circles to be a problem, a Java pen test questions. Had seen enough already Tucao as weakness, but this could not bear it for another one broke out. Written too long to open a separat

  • Subject: Please do not take the "String s = new String (" xyz "); create a number of String instances" to the interview now 2010-12-02

    Had seen enough already Tucao as weakness, but this could not bear it for another one broke out. Written too long to open a separate post altogether. Incidentally Advertising: The JVM students interested comrades please support high-level language vi

  • public static void main (String args []) parameters 2010-05-15

    String args [] is the main function of main parameters, namely array of strings. Using eclipse in the editing, right-click to run the Java files in the Run As option, select Run Configurations. Main class in the Project and complete the project, resp

  • Object is converted to JSON string 2010-03-29

    Keywords: json package; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; / ** * Providing the object is converted to JSON string method * @ Author author Li Youth * @ Version Version 0.01 * @ Filename

  • Java String object, the classic problem of (new String ()) [switch] 2011-08-05

    Look at an example, the code is as follows: Java code public class Test { public static void main (String [] args) { String str = "abc"; String str1 = "abc"; String str2 = new String ("abc"); System.out.println (str == str1);

  • javaBean与Map String,Object 互转 2014-04-15

    1. 为什么要实现javaBean与Map<String,Object>相互转换? 用过spring的都知道spring的MVC框架中有一个BaseCommandController对象,利用这个对象我们就可以很方便的将从客户端传递过来的参数封装到一个JavaBean对象中去,而不需要我们request.getParameter("name");bean.setName(name);了,从而也简化了不少的工作.如果大家用过BeanUtils.populate的话,就知道,这

  • String object understanding in progress 2008-06-12

    In-depth JAVA virtual machine "is so described in the book: JVM run-time data area of memory model consists of five parts: [1] [2] methods that heap [3] JAVA stack [4] [5] PC register native method stacks For String s = "haha", its virtual

  • Java String object on a small summary in the 2011-05-05

    String is a pair of double quotes character sequence, in the JAVA language, the string data is actually achieved by the String class. Java string class is divided into two types: one is the change in the program will not be the same length of string;

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C), All Rights Reserved. 版权所有 黔ICP备15002463号-1

processed in 0.474 (s). 12 q(s)