This discussion is archived
0 Replies Latest reply: Jun 20, 2008 2:56 AM by 843844 RSS

How to Run a JasperReport in  web application

843844 Newbie
Currently Being Moderated
hi ,
I am Deepan,
Proffesional:Programmer,

I Used the Ireport for jasper Report,Iam Running in webApplication(JSP,Tomcat as Server),
I used the line
JasperViewer.viewReport(jasperPrint,false);

it work well in server system,that is where the Apache Tomcat is installed,It displayed the Print format for Taking Print,
Well,when i run the application in client System,PrintFormat get Displayed in Server System(Tomcat installed),
But i need the PrintFormat to display in Client System ,Where they Work...
Help Me,
Thanks iN advance....

I attached the Code here for reference
(Line in Bold)
package jasper.testpkg;

//import static chequebook.db.Conf.getAppHome;

import java.util.HashMap;

import java.util.Vector;
//import java.util.ArrayList;
//import model.Load;
import model.BillPrePrintModel;

import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.view.JasperViewer;
//import chequebook.vo.ChequeBookVO;

public class BillPrePrint {

public static JasperTestCustomDataSource getDefaultCustomDS(String billno){
     //String billno="";
     JasperTestCustomDataSource customDataSource = new JasperTestCustomDataSource();
     BillPrePrintModel bpm=new BillPrePrintModel();
//String billno="";
Vector billdata=bpm.Collectbilldata(billno);
String mybillno="",mybilldate="",mybillcustomer="",mybilltoaddress="",mybilltotal="0" ;

System.out.println("billData"+billdata);
if(billdata.size()!=0)
{     mybilltotal=billdata.get(billdata.size()-5).toString();
     mybillno=billdata.get(billdata.size()-4).toString();
     mybilldate=billdata.get(billdata.size()-3).toString();
     mybillcustomer=billdata.get(billdata.size()-2).toString();
     mybilltoaddress=billdata.get(billdata.size()-1).toString();
     System.out.println("MYBILLNO:"+mybillno);
     System.out.println("MYBILLDATE:"+mybilldate);
}


     JasperTestDataVO dataDS = new JasperTestDataVO();
     dataDS.setBillNo(mybillno);
     dataDS.setBillDate(mybilldate);
     dataDS.setBillFrom(mybillcustomer);
     dataDS.setBillTo(mybilltoaddress);
     dataDS.setTotamount(mybilltotal);


     JasperTestLineDataVO line = null;
     dataDS.setLineData(new Vector<JasperTestLineDataVO>());

//line = new JasperTestLineDataVO();

System.out.println("Vector Bill Data"+billdata);

/*
     private String fdate="";
     private String regno="";
     private String gcno="";
     private String ffrom="";
     private String fto="";
     private String docref="";
     private String pkgs="";
     private String weight="";
     private String trucktype="";
     private String amount="0";
     private String totalamt="0";


*/

     for(int i=0;i<billdata.size()-5;i+=10)
     {
          line = new JasperTestLineDataVO();
          line.setFdate(billdata.get(i).toString());
          line.setRegno(billdata.get(i+1).toString());
          line.setGcno(billdata.get(i+2).toString());
          line.setFfrom(billdata.get(i+3).toString());
          line.setFto(billdata.get(i+4).toString());
          line.setDocref(billdata.get(i+5).toString());
          line.setPkgs(billdata.get(i+6).toString());
          line.setWeight(billdata.get(i+7).toString());
          line.setTrucktype(billdata.get(i+8).toString());
          line.setAmount(billdata.get(i+9).toString());

          dataDS.getLineData().add(line);

               System.out.println("billdata.get(i).toString()"+billdata.get(i).toString());
               System.out.println("billdata.get(i+1).toString()"+billdata.get(i+1).toString());
               System.out.println("Checking Line Loop"+ (i+1));




     }
     /*
     line.setItemName("Item Type 1");
     line.setLineNum("1");
     line.setPrice("1.09");
     line.setQty("100");
     dataDS.getLineData().add(line);

     line = new JasperTestLineDataVO();
     line.setItemName("Item Type 2");
     line.setLineNum("2");
     line.setPrice("2.09");
     line.setQty("50");
     dataDS.getLineData().add(line);

     line = new JasperTestLineDataVO();
     line.setItemName("Item Type 3");
     line.setLineNum("3");
     line.setPrice("3.19");
     line.setQty("25");
     dataDS.getLineData().add(line);*/
customDataSource.setDataDS(dataDS);
return customDataSource;
}

     public void MyImp(String billno){

          JasperDesign jasperDesign;
          try {

               //System.out.println("billdata"+billdata);
               jasperDesign = JRXmlLoader.load("C:\\Program Files\\Apache Software Foundation\\Tomcat 5.0\\webapps\\Cargo\\WEB-INF\\RMPrePrint.jrxml");
               JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);

               HashMap param = new HashMap();

               JasperPrint jasperPrint;
               jasperPrint = JasperFillManager.fillReport(jasperReport, param,getDefaultCustomDS(billno));

               JasperExportManager.exportReportToHtmlFile(jasperPrint,"D:\\TEstJagan1.html");

               //JasperExportManager.exportReportToHtmlFile(jasperPrint,"D:\\TEst.html");
               System.out.println("your file updated to HTML file ");

               JasperViewer.viewReport(jasperPrint,false);_




          } catch (JRException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
          }
     }

}

class JasperTestDataVO{
     private String billNo="";
     private String billDate="";
     private String billFrom="";
     private String billTo="";
     private String totalamt="0";

     Vector<JasperTestLineDataVO> lineData=new Vector<JasperTestLineDataVO>();

     public Vector<JasperTestLineDataVO> getLineData(){
          return lineData;
     }


     public void setLineData(Vector<JasperTestLineDataVO> pData){
          lineData=pData;
     }
     public String getBillDate() {
          return billDate;
     }
     public void setBillDate(String billDate) {
          this.billDate = billDate;
     }
     public String getBillNo() {
          return billNo;
     }
     public void setBillNo(String billNo) {
          this.billNo = billNo;
     }

     public String getBillFrom() {
          return billFrom;
     }
     public void setBillFrom(String billFrom) {
          this.billFrom = billFrom;
     }


     public String getBillTo() {
          return billTo;
     }


     public void setBillTo(String billTo) {
          this.billTo = billTo;

}




public String getTotamount() {
          return totalamt;
     }
     public void setTotamount(String totalamt) {
          this.totalamt = totalamt;
     }




     }




class JasperTestLineDataVO{
     private String lineNum="";
     private String itemName="";
     private String qty="0";
     private String price="0";


     private String fdate="";
     private String regno="";
     private String gcno="";
     private String ffrom="";
     private String fto="";
     private String docref="";
     private String pkgs="";
     private String weight="";
     private String trucktype="";
     private String amount="0";


     //regno="",gcno="",ffrom="",fto="",docref="",pkgs="",weight="",trucktype="",amount="",totalamt="0";



     public String getFdate() {
          return fdate;
     }
     public void setFdate(String fdate) {
          this.fdate = fdate;
     }

     public String getRegno() {
          return regno;
     }
     public void setRegno(String regno) {
          this.regno = regno;
     }
     public String getGcno() {
          return gcno;
     }
     public void setGcno(String gcno) {
          this.gcno = gcno;
     }



public String getFfrom() {
          return ffrom;
     }
     public void setFfrom(String ffrom) {
          this.ffrom = ffrom;
     }

public String getFto() {
          return fto;
     }
     public void setFto(String fto) {
          this.fto = fto;
     }

public String getDocref() {
          return docref;
     }
     public void setDocref(String docref) {
          this.docref = docref;
     }

public String getPkgs() {
          return pkgs;
     }
     public void setPkgs(String pkgs) {
          this.pkgs = pkgs;
     }


public String getWeight() {
          return weight;
     }
     public void setWeight(String weight) {
          this.weight = weight;
     }


public String getTrucktype() {
          return trucktype;
     }
     public void setTrucktype(String trucktype) {
          this.trucktype = trucktype;
     }

public String getAmount() {
          return amount;
     }
     public void setAmount(String amount) {
          this.amount = amount;
     }


}
class JasperTestCustomDataSource implements JRDataSource{
     int size = 0;
     int index=-1;

     private JasperTestDataVO dataDS=null;

     public void setDataDS(JasperTestDataVO pDataDS){
          dataDS=pDataDS;
          size=pDataDS.getLineData().size();
          System.out.println("LineData Size"+String.valueOf(size));
     }
     public Object getFieldValue(JRField f) throws JRException {
          // TODO Auto-generated method stub

          String trucktype="";
          Object ret=null;

          if(f.getName().equals("billno")){
                              ret=dataDS.getBillNo();

          }
          if(f.getName().equals("billdate")){
                              ret=dataDS.getBillDate();

          }
          if(f.getName().equals("toaddress")){
                              ret=dataDS.getBillFrom();

          }



          if(f.getName().equals("bytoaddress")){
                              ret=dataDS.getBillTo();
          }


          if(f.getName().equals("fdate")){
                         ret=dataDS.getLineData().get(index).getFdate();
          }

if(f.getName().equals("regno")){
                         ret=dataDS.getLineData().get(index).getRegno();
          }

if(f.getName().equals("gcno")){
                         ret=dataDS.getLineData().get(index).getGcno();
          }
if(f.getName().equals("from")){
                                   ret=dataDS.getLineData().get(index).getFfrom();
          }
if(f.getName().equals("to")){
                         ret=dataDS.getLineData().get(index).getFto();
          }



if(f.getName().equals("docref")){
                         ret=dataDS.getLineData().get(index).getDocref();
          }

System.out.println("Index inside"+String.valueOf(index));


if(f.getName().equals("pkgs")){
                         ret=dataDS.getLineData().get(index).getPkgs();
          }

if(f.getName().equals("weight")){
                         ret=dataDS.getLineData().get(index).getWeight();
          }

if(f.getName().equals("trucktype")){
                         ret=dataDS.getLineData().get(index).getTrucktype();
          }


          trucktype=String.valueOf(dataDS.getLineData().get(index).getTrucktype());
          System.out.println("TRuck Type:::::"+index+":::"+trucktype);

if(f.getName().equals("amount")){
                         ret=dataDS.getLineData().get(index).getAmount();
          }
if(f.getName().equals("total")){
                         ret=dataDS.getTotamount();
          }



          return ret;
     }

     public boolean next() throws JRException {
          // TODO Auto-generated method stub
          index++;

          System.out.println("Index"+String.valueOf(index));
          boolean ret=true;
          if(index>=size){
               ret =false;
          }

          return ret;
     }

}