编译报告时出错,错误是:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: javax/servlet/ServletOutputStream
这是代码:
Map parameter = new HashMap();
parameter.put("customerId", notification_table.getValueAt(r, 0).toString());
ReportV sd = new ReportV();
sd.showReport(parameter);
这是我使用的课程:
import java.sql.*;
import java.util.Map;
import javax.swing.*;
import static javax.swing.JFrame.EXIT_ON_CLOSE;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.swing.JRViewer;
public class ReportV {
Connection conn = null;
void showReport(Map parameters) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:pcn");
JasperReport report = JasperCompileManager.compileReport("recipt.jrxml");
JasperPrint print = JasperFillManager.fillReport(report, parameters, conn);
JRViewer viewer = new JRViewer(print);
viewer.setOpaque(true);
viewer.setVisible(true);
//make your JFrame visible
this.add(viewer);
this.setSize(300, 200);
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
} catch (Exception ex) {
System.out.println("CAUSE: " + ex.getCause());
System.out.println("MESSAGE" + ex.getMessage());
System.out.println("LOCAL MESSAGE" + ex.getLocalizedMessage());
ex.printStackTrace();
}
}
}
答案 0 :(得分:1)
您尚未导入ServletOutputStream
类。
import javax.servlet.ServletOutputStream;
我相信这是Java EE的一部分,所以除了标准的java jdk之外,你还需要在类路径中使用lib。