Error while creating Jasper Report using jsp and servlet

I am creating web application in Java (my first project in Java) and I have to create Reports in that.

I’m using iReport to generate the reports.
using some reference code I have created my servlet code..
but I’m getting java.lang.ClassNotFoundException

Or can someone please share some sample code or example to generate jsper report with servlate
here is my code:

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stu
    ServletContext ctx = request.getServletContext();
    String reportTemplateFilePath = ctx.getRealPath("D:/Reports/DemoReport.jrxml");
    ByteArrayOutputStream reportStream = getReportOutputStream(reportTemplateFilePath);

    ServletOutputStream servletOutputStream =  response.getOutputStream();

private ByteArrayOutputStream getReportOutputStream(String reportTemplateFilePath) {
      JasperReport jasperReport;
      ByteArrayOutputStream outputstream = new ByteArrayOutputStream();
      JasperPrint jasperPrint;
      try {
          jasperReport = JasperCompileManager.compileReport(reportTemplateFilePath);
          Map<String, Object> reportParameters = new HashMap<>();
          jasperPrint = JasperFillManager.fillReport(jasperReport, reportParameters, getConnection());
          JRExporter exporter = new JRPdfExporter();
          exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
          exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputstream);
      } catch (JRException e) {
      return outputstream;

Source: jsp

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.