質問

I imported net.sf.json package to use the feature of JSON in my jsp apge but as soon as I create an object of JSONArray it throws me NoClassDefinitionFound.

//line 50
JSONObject responcedata=new JSONObject();


exception thrown is:
org.apache.jasper.JasperException: An exception occurred processing JSP page /jqgriddata.jsp at line 50


48: 
49: 
50:         JSONObject responcedata=new JSONObject();
51:         JSONArray cellarray=new JSONArray();
52: 
53:   //      responcedata.put("total",totalrow);


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:401)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause

javax.servlet.ServletException: java.lang.NoClassDefFoundError: Could not initialize class net.sf.json.JSONObject
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
    org.apache.jsp.jqgriddata_jsp._jspService(jqgriddata_jsp.java:191)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause

java.lang.NoClassDefFoundError: Could not initialize class net.sf.json.JSONObject
    org.apache.jsp.jqgriddata_jsp._jspService(jqgriddata_jsp.java:100)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:

260) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

役に立ちましたか?

解決

It's just telling that the mentioned class is missing in the webapp's runtime classpath. You need to download and drop the JAR file holding the classes of net.sf.json package in /WEB-INF/lib folder (don't forget to do the same for its dependencies as well, if necessary).


Unrelated to the concrete problem: writing Java code in a JSP file is a poor practice. Reading Roseindia.net tutorials is also a very bad idea as they only shows bad practices.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top