How to print Jasper reports from servlets?

589 views Asked by At

I am trying to print a Jasper report from my web application's servlet. Below is the code which calls the printing function.

//Print the report
                HashMap<String, Object> params = new HashMap<String, Object>();
                params.put("companyName",userBean.getCompanyName().trim());
                params.put("companyPhone",userBean.getPhone().trim());
                params.put("patientName",demographicsBean.get(0).getfName()+" "+demographicsBean.get(0).getmName()+" "+demographicsBean.get(0).getlName());
                params.put("patientAge",String.valueOf(demographicsBean.get(0).getDob()));
                params.put("address",demographicsBean.get(0).getAdrLine1()+" "+demographicsBean.get(0).getAdrLine2());
                java.util.Date date = new java.util.Date(); 
                params.put("date",String.valueOf(new Date(Calendar.getInstance().getTimeInMillis())));
                params.put("doctorName",subUserBean.getFirstName()+" "+subUserBean.getLastName());
                params.put("drugName",drug);
                params.put("ptInstructions",ptInstructionsTxt);
                params.put("quantity",request.getParameter("quantityTxt"));
                params.put("refills",refilTxt);

                  Connection connection = DBMaster.getInstance().getConnection();

                ReportConnector r = new ReportImpl();                
                r.printReport(getClass().getResourceAsStream("/ReportResources/Prescription2.jasper"), params,connection); 

Below is the code printing the report.

public void printReport(InputStream path, Map<String, Object> params, Connection con) throws JRException
    {
       JasperPrint jasperPrint = JasperFillManager.fillReport(path, params, con);

       JasperPrintManager.printReport(jasperPrint, false);
    }

The issue is, eventhough this worked in localhost, nothing is getting printed (I do not have a printer now, but MS One Note should be open as the printer. That is happening in localhost).

what is wrong here?

0

There are 0 answers