0

I have create a code to download pdf using struts 2. but when i run it it will throw exception...

Struts has detected an unhandled exception:

Messages:

org.apache.commons.logging.LogFactory
org/apache/commons/logging/LogFactory

File: org/apache/catalina/loader/WebappClassLoaderBase.java

Line number: 1,313

here is my code snapshot... where I face the exceptions ...

  public String execute() throws Exception {
    try {
        if (submit.equals("pdf")) {
            rs = new ReportDAO().getPdf();
            jasperPath = ServletActionContext.getServletContext().getRealPath("/Reports");
            pdfName = "Studnet Report";
            rpt = "studentReport.jrxml";
   // I got error at this line....
            JRResultSetDataSource resultSetDataSource = new JRResultSetDataSource(rs);
            HashMap<String, Object> pm = new HashMap<String, Object>();
            String logo = jasperPath + "/ws.jpg";
            pm.put("logo", logo);
            JasperReport jr = JasperCompileManager.compileReport(jasperPath + "/" + rpt);
            System.out.println("ok");
            JasperPrint jp = JasperFillManager.fillReport(jr, pm, resultSetDataSource);
            JasperExportManager.exportReportToPdfFile(jp, jasperPath + pdfName + ".pdf");
            fileInputStream = new FileInputStream(new File(jasperPath + pdfName + ".pdf"));

        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "SUCCESS";

}

struts.xml

  <result name="SUCCESS" type="stream">
            <param name="contentType">application/octet-stream</param>
            <param name="inputName">fileInputStream</param>
            <param name="contentDisposition">attachment;filename="${pdfName}.pdf"</param>
            <param name="bufferSize">1024</param>
        </result>

Exception:

java.lang.reflect.InvocationTargetException

sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source) 

java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

net.sf.jasperreports.engine.util.JRLoader.(JRLoader.java:67)
net.sf.jasperreports.engine.JRPropertiesUtil.loadProperties(JRPropertiesUtil.java:99)
net.sf.jasperreports.engine.DefaultJasperReportsContext.initProperties(DefaultJasperReportsContext.java:94)

java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory

org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1313)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1164)
net.sf.jasperreports.engine.util.JRLoader.(JRLoader.java:67)
Alex K
  • 22,315
  • 19
  • 108
  • 236
Baba Ramdev
  • 13
  • 1
  • 5
  • Possible duplicate of [Getting java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory exception](http://stackoverflow.com/questions/1551697/getting-java-lang-classnotfoundexception-org-apache-commons-logging-logfactory) – Alex K Nov 09 '16 at 07:44

2 Answers2

0

Try to download this jar files.

commons-logging library

then paste it in WEB-INF/lib on your Web content.

It says that your commons-logging library is not found.

hope it will helps.

msagala25
  • 1,806
  • 2
  • 17
  • 24
-1

Have you got the commons-logging library?

Noel Murphy
  • 1,264
  • 1
  • 8
  • 12