jsp - Not able to display a Jasper report on the browser , Allocate exception for servlet JaspersJob_servlet java.lang.ClassNotFoundException -
help me out have issue jasper report on servlet, error mentioned below
severe: allocate exception servlet jaspersjob_servlet java.lang.classnotfoundexception: net.sf.jasperreports.engine.jrruntimeexception @ org.apache.catalina.loader.webappclassloader.loadclass(webappclassloader.java:1680) @ org.apache.catalina.loader.webappclassloader.loadclass(webappclassloader.java:1526) @ java.lang.class.getdeclaredconstructors0(native method) @ java.lang.class.privategetdeclaredconstructors(unknown source) @ java.lang.class.getconstructor0(unknown source) @ java.lang.class.newinstance(unknown source) @ org.apache.catalina.core.standardwrapper.loadservlet(standardwrapper.java:1149) @ org.apache.catalina.core.standardwrapper.allocate(standardwrapper.java:827) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:129) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:191) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:127) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:103) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:109) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:293) @ org.apache.coyote.http11.http11processor.process(http11processor.java:861) @ org.apache.coyote.http11.http11protocol$http11connectionhandler.process(http11protocol.java:606) @ org.apache.tomcat.util.net.jioendpoint$worker.run(jioendpoint.java:489) @ java.lang.thread.run(unknown source)
servlet code:
package jasper_job_print; import java.io.file; import java.io.ioexception; import java.io.printwriter; import java.sql.*; import javax.servlet.servletexception; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import net.sf.jasperreports.engine.*; import net.sf.jasperreports.engine.design.jrdesignquery; import net.sf.jasperreports.engine.export.jrpdfexporter; import net.sf.jasperreports.engine.util.jrloader; public class jaspersjob_servlet extends httpservlet { private static final long serialversionuid = -3478873702336546526l; protected void service(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { connection con=null; file reportfile = null; jasperprint jasperprint = null; resultset rs=null; statement statement = null; try { class.forname("com.mysql.jdbc.driver"); con = drivermanager.getconnection("jdbc:mysql://localhost:3306/cloudinterdataset", "root","cosmos123"); reportfile = new file("c:\\abd\\jasperjava\\report10.jasper"); string sql1 = "select * userdetails " + "order lastname "; statement = con.createstatement(); rs = statement.executequery(sql1); if (!reportfile.exists()) throw new jrruntimeexception( "file webappreport.jasper not found. report design must compiled first."); } catch(exception e) { system.out.println("exception : "+e); } try { jrresultsetdatasource resultsetdatasource = new jrresultsetdatasource(rs); system.out.println("filling jasper pdf report..."); jasperreport jasperreport = (jasperreport) jrloader .loadobject(reportfile.getpath()); jasperprint = jasperfillmanager.fillreport(jasperreport,null,resultsetdatasource); system.out.println("done!"); if (jasperprint != null) { jrexporter exporter = null; exporter = new jrpdfexporter(); exporter.setparameter(jrexporterparameter.jasper_print, jasperprint); exporter.setparameter(jrexporterparameter.output_stream, response.getoutputstream()); exporter.exportreport(); } else { response.setcontenttype("text/html"); printwriter out = response.getwriter(); out.println("<html>"); out.println("<head>"); out.println("<title>jasperreports </title>"); out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"../stylesheet.css\" title=\"style\">"); out.println("</head>"); out.println("<body bgcolor=\"white\">"); out.println("<span class=\"bold\">empty response.</span>"); out.println("</body>"); out.println("</html>"); } } catch(exception e) { system.out.println("exception :"+e); } }
}
is simple solution did not put jar files in project lib. working now, got time post answer
Comments
Post a Comment