Setelah selesai mendevelop file .jrxml menggunakan iReport, copy file ini ke dalam WEB-INF. kemudian klik kanan pada project dan pilih “clean and build project” tunggu sampai selesai. Tambahkan satu tombol dan masukkan kode dibawa ini (sesuaikan dengan kebutuhan anda). Selamat mencoba
Setelah selesai mendevelop file .jrxml menggunakan iReport, copy file ini ke dalam WEB-INF. kemudian klik kanan pada project dan pilih “clean and build project” tunggu sampai selesai. Tambahkan satu tombol dan masukkan kode dibawa ini (sesuaikan dengan kebutuhan anda). Selamat mencoba
import java.util.*;
import net.sf.jasperreports.engine.*;
import java.io.*;
import java.sql.*;
import net.sf.jasperreports.view.*;
import net.sf.jasperreports.view.save.*;
public class mybean
{
Statement stmt1;
Connection con1;
JasperReport jasperReport;
JasperPrint jasperPrint;
JRResultSetDataSource obj;
ResultSet rs3;
String i,j;
String salarys,salarye,butValue1;
String pdftext,csvtext,htmltext,xmltext,exceltext,wordtext,path;
public void setSalarys(String salarys)
{
this.salarys=salarys;
}
public void setSalarye(String salarye)
{
this.salarye=salarye;
}
public String getSalarys()
{
return salarys;
}
public String getSalarye()
{
return salarye;
}
public void setbutValue1(String butValue1)
{
this.butValue1=butValue1;
}
public String getbutValue1()
{
return butValue1;
}
public void setPdftext(String pdftext)
{
this.pdftext=pdftext;
}
public void setHtmltext(String htmltext)
{
this.htmltext=htmltext;
}
public void setXmltext(String xmltext)
{
this.xmltext=xmltext;
}
public void setCsvtext(String csvtext)
{
this.csvtext=csvtext;
}
public void setExceltext(String exceltext)
{
this.exceltext=exceltext;
}
public void setWordtext(String wordtext)
{
this.wordtext=wordtext;
}
/////////
public String getPdftext()
{
return pdftext;
}
public String getHtmltext()
{
return htmltext;
}
public String getXmltext()
{
return xmltext;
}
public String getCsvtext()
{
return csvtext;
}
public String getExceltext()
{
return exceltext;
}
public String getWordtext()
{
return wordtext;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public void dataOut()
{
try
{
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
con1=DriverManager.getConnection(“jdbc:odbc:abcDSN”,”root”,”");
stmt1=con1.createStatement();
rs3=stmt1.executeQuery(“select *from info where salary>”+salarys+” AND salary<”+salarye+”");
obj = new JRResultSetDataSource(rs3);
jasperReport = JasperCompileManager.compileReport(“C:/Documents and Settings/srikanth/Desktop/vani/WEB-INF/simple2.jrxml”);
jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap(),obj);
}catch(Exception e){System.out.println(e);}
}
public String genPdfReport()
{
try
{
JasperExportManager.exportReportToPdfFile(jasperPrint,”C:/Documents and Settings/srikanth/Desktop/”+pdftext+”.pdf”);
System.out.println(“your file updated to pdf file plz check pdf file on desktop”);
path=”C:/Documents and Settings/srikanth/Desktop/”+pdftext+”.pdf”;
}catch(Exception ee){System.out.println(ee);}
return path;
}
public String genHtmlReport()
{
try
{
JasperExportManager. exportReportToHtmlFile(jasperPrint,”C:/Documents and Settings/srikanth/Desktop/”+htmltext+”.html”);
System.out.println(“your file updated to HTML file plz check pdf file on desktop”);
}catch(Exception eee){System.out.println(eee);}
path=”C:/Documents and Settings/srikanth/Desktop/”+htmltext+”.html”;
return path;
}
public String genXmlReport()
{
try
{
JasperExportManager.exportReportToXmlFile(jasperPrint,”C:/Documents and Settings/srikanth/Desktop/”+xmltext+”.xml”,true);
System.out.println(“your file updated to XML file plz check pdf file on desktop”);
} catch(Exception eeee){System.out.println(eeee);}
path=”C:/Documents and Settings/srikanth/Desktop/”+xmltext+”.xml”;
return path;
}
public String genExcelReport()
{
try
{
JRSingleSheetXlsSaveContributor excelobj = new JRSingleSheetXlsSaveContributor() ;
File f1 = new File(“C:/Documents and Settings/srikanth/Desktop/”+exceltext+”");
excelobj.save(jasperPrint,f1);
}catch(Exception eeeee){System.out.println(eeeee);}
path=”C:/Documents and Settings/srikanth/Desktop/”+exceltext+”.xls”;
return path;
}
public String genWordReport()
{
try
{
File f2 = new File(“C:/Documents and Settings/srikanth/Desktop/”+wordtext+”");
JRRtfSaveContributor rtfobj = new JRRtfSaveContributor();
rtfobj.save(jasperPrint,f2);
}catch(Exception eeeeee){System.out.println(eeeeee);}
path=”C:/Documents and Settings/srikanth/Desktop/”+wordtext+”.doc”;
return path;
}
public String genCsvReport()
{
try
{
File f3 = new File(“C:/Documents and Settings/srikanth/Desktop/”+csvtext+”");
JRCsvSaveContributor csvobj = new JRCsvSaveContributor();
csvobj.save(jasperPrint,f3);
}catch(Exception eeeeeee){System.out.println(eeeeeee);}
path=”C:/Documents and Settings/srikanth/Desktop/”+csvtext+”.csv”;
return path;
}
public String getPath()
{
return path;
}
}
Posted by aq on April 4, 2008 at 7:03 am
lumayanlah,walaupun g jelas..
Posted by blackstar on February 4, 2009 at 9:53 am
mm… mau nanya!! knp nyimpennya harus di WEB-INF?
klo g di WEB-INF bisa g?
aku nyoba di jsp ky gni :
String jrxmlPath = “/jrxml/events/export1PDF.jrxml”;
Map parameters = new HashMap();
parameters.put(“Q_CONDITION”, “”);
parameters.put(“Q_ORDER”, “”);
DBLib dbase = new DBLib();
dbase.myConnection(“localhost”, “nms”, “root”, “”); //set the connectivity for DBLib
JasperReport jasperReport = JasperCompileManager.compileReport(jrxmlPath);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, dbase.getCon());
JasperExportManager.exportReportToPdfFile(jasperPrint, “/jrxml/events/exportPDF.pdf”);
JasperViewer.viewReport(jasperPrint);
Tapi yang keluar mlh blank page.. tanpa output n hasilnya g ada..
bisa bantu gak?