0

I am calling my java method from jsp its giving NoClassDefFoundError: error.

But my method is working when i am calling from the main method. i have used xlrd jar in my code and i have placed the jar lib folder as well. but still it gives error.

Exception trace:

org.apache.jasper.JasperException: An exception occurred processing JSP page /exportDSD.jsp at line 20 17: //excel.getExcel(); 18: 19: Report r = new Report(); 20: r.generateReport(); 21: 22: System.out.println("Generated DSD"); 23: %> 

Stacktrace:

org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339) javax.servlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 

root cause :

javax.servlet.ServletException: java.lang.NoClassDefFoundError: xlrd/Workbook org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:916) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:845) org.apache.jsp.exportDSD_jsp._jspService(exportDSD_jsp.java:107) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339) javax.servlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 

My code :

import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.hssf.usermodel.HSSFDataFormat; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import xlrd.*; public void generateReport() throws BiffException, ClassNotFoundException, SQLException, IOException { ... ... } 

From jsp i am calling like this:

<% Report r =new Report(); r.generateReport(); %> 
6
  • Here is my code: import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.hssf.usermodel.HSSFDataFormat; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import xlrd.*; public void generateReport() throws BiffException, ClassNotFoundException, SQLException, IOException { ... ... } From jsp i am calling like this: <% Report r =new Report(); r.generateReport(); %> Commented Jun 2, 2015 at 6:32
  • 1
    Please add the code to your question using the edit function. Not as a comment. Commented Jun 2, 2015 at 6:34
  • I cannot read you code. post it in ques (formatted) Commented Jun 2, 2015 at 6:34
  • Share your jsp code...may be imports not correct Commented Jun 2, 2015 at 6:36
  • These are my imports in jsp <%@ page language="java" import = "com.sample.Report"%> <%@ page language="java" import = "xlrd.*"%> Commented Jun 2, 2015 at 6:44

3 Answers 3

4

Appears JSP import not correct:

Add jar in WEB-INF/lib Add <%@ page import="xlrd.*" %> to the top of your JSP 

To import more than one classes, use the following format:

<%@ page import="com.sample.Report,xlrd.*" %> 
Sign up to request clarification or add additional context in comments.

Comments

0

The issue is with jar containing Workbook in some jar. Put it in the WEB-INF/lib folder. I don't think, this need to be included in the JSP as well.

Comments

0

NoClassDefFoundError is a JVM Error which means that JVM or class loader was not able to load the class definition. This means that class was found but due to some reason JVM or class loader was not able to load the class definition.
java.lang.NoClassDefFoundError: xlrd/Workbook doesn't mean that class was not found, if that was the case you would have got ClassNotFoundException. On contrary, class file was found but JVM is unable to load the class definition.

For NoClassDefFoundError you can check source of xlrd/Workbook if it contains some static block or member which is referencing some class which is not present or causing issue at runtime.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.