Error Compiling Report: java.lang.NoClassDefFoundError: javax/servlet/ServletOutputStream

心已入冬 提交于 2019-12-20 07:47:29

问题


I have an error while compiling report the error is:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: javax/servlet/ServletOutputStream

this is the code:

Map parameter = new HashMap();
parameter.put("customerId", notification_table.getValueAt(r, 0).toString());
ReportV sd = new ReportV();
sd.showReport(parameter);

this is the class I used:

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();
        }
    }
}

回答1:


you have not imported the ServletOutputStream class.

import javax.servlet.ServletOutputStream;

I believe that's part of Java EE, so you will need that lib in your classpath in addition to the standard java jdk.



来源:https://stackoverflow.com/questions/21791371/error-compiling-report-java-lang-noclassdeffounderror-javax-servlet-servletout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!