我被JasperReports困住了。我使用iReport开发了报告。当我在iReport中运行报表时,它运行得很好。但是当我在我的应用程序中通过servlet调用报告时,对于第一次调用,它工作正常。如果我第二次调用报告,则显示为"文档没有页面"即使我的数据库有所需的数据。再次,如果我重新启动我的tomcat服务器并调用相同的报告,它再次正常工作。当我再打一次电话时报告问题。谁能在这帮助我?
public class Repor extends JFrame {
HashMap hm = null;
Connection con = null;
String reportName;
public Repor() {
setExtendedState(MAXIMIZED_BOTH);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
public Repor(HashMap map) {
this.hm = map;
setExtendedState(MAXIMIZED_BOTH);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
public Repor(HashMap map, Connection con) {
this.hm = map;
this.con = con;
setExtendedState(MAXIMIZED_BOTH);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setTitle("Report Viewer");
}
public void setReportName(String rptName) {
this.reportName = rptName;
}
public void callReport() {
JasperPrint jasperPrint = generateReport();
JRViewer viewer = new JRViewer(jasperPrint);
Container c = getContentPane();
c.add(viewer);
this.setVisible(true);
}
public void callConnectionLessReport() {
JasperPrint jasperPrint = generateEmptyDataSourceReport();
JRViewer viewer = new JRViewer(jasperPrint);
Container c = getContentPane();
c.add(viewer);
this.setVisible(true);
}
public void closeReport() {
}
/** this method will call the report from data source*/
public JasperPrint generateReport() {
try {
if (con == null) {
try {
con = Database.getConnection();
} catch (Exception ex) {
ex.printStackTrace();
}
}
JasperPrint jasperPrint = null;
if (hm == null) {
hm = new HashMap();
}
try {
/**You can also test this line if you want to display
* report from any absolute path other than the project root path*/
jasperPrint = JasperFillManager.fillReport(reportName , hm, con);
} catch (JRException e) {
e.printStackTrace();
}
return jasperPrint;
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
/** call this method when your report has an empty data source*/
public JasperPrint generateEmptyDataSourceReport() {
try {
JasperPrint jasperPrint = null;
if (hm == null) {
hm = new HashMap();
}
try {
jasperPrint = JasperFillManager.fillReport(reportName + ".jasper", hm, new JREmptyDataSource());
} catch (JRException e) {
e.printStackTrace();
}
return jasperPrint;
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
}