naresh126 Posted November 4, 2009 Share Posted November 4, 2009 Hi my name is Naresh.I am new to this forum.I was trying to generate a report in PDF format from a web browser using jasper reports but am getting the following error.http://localhost:8080/Demos/DbReportServletfile path:- C:\Tomcat\webapps\Demos\WEB-INF\classes\DbReportServlet.classjavax.servlet.ServletException: Error allocating a servlet instance org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454) java.lang.Thread.run(Thread.java:619) root causejava.lang.NoClassDefFoundError: DbReportServlet (wrong name: net/ensode/jasperbook/DbReportServlet) java.lang.ClassLoader.defineClass1(Native Method) java.lang.ClassLoader.defineClass(ClassLoader.java:621) java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124) org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1850) org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:890) org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1354) org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454) java.lang.Thread.run(Thread.java:619)I used report1.jasper as the input file in the DbReportServlet.java file and i compiled it and made changes in the web.xml file and also stored my class file in "Classes" folder of web-inf.I did everything as mention in the Jasperreports tutorials and wat saw in google searches.But still am gettin this error.Please let me know if am doin any mistakes in the code or anything else.Thanks in Advance.Code:package net.ensode.jasperbook;import java.io.IOException;import java.io.InputStream;import java.io.PrintWriter;import java.io.StringWriter;import java.sql.Connection;import java.sql.DriverManager;import java.util.HashMap;import javax.servlet.ServletException;import javax.servlet.ServletOutputStream;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import net.sf.jasperreports.engine.JasperRunManager;public class DbReportServlet extends HttpServlet{protected void doGet(HttpServletRequest request, HttpServletResponseresponse) throws ServletException, IOException{Connection connection;ServletOutputStream servletOutputStream =response.getOutputStream();InputStream reportStream =getServletConfig().getServletContext().getResourceAsStream("C:\\Jasper_Reports\\report1.jasper");try{Class.forName("com.mysql.jdbc.Driver");connection = DriverManager.getConnection ("jdbc:mysql://localhost:8080?user=dbuser&password=secret");JasperRunManager.runReportToPdfStream(reportStream,servletOutputStream, new HashMap(), connection);connection.close();response.setContentType("application/pdf");servletOutputStream.flush();servletOutputStream.close();}catch (Exception e){// display stack trace in the browserStringWriter stringWriter = new StringWriter();PrintWriter printWriter = new PrintWriter(stringWriter);e.printStackTrace(printWriter);response.setContentType("text/plain");response.getOutputStream().print(stringWriter.toString());}}} Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now