我导入 net.sf.json 包以在我的 jsp apge 中使用 JSON 的功能,但是一旦我创建了一个对象它的JSONArray引发了我 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)
答案 0 :(得分:4)
它只是告诉webapp的运行时类路径中缺少所提到的类。您需要download并删除在net.sf.json
文件夹中保存/WEB-INF/lib
包类的JAR文件(如果需要,也不要忘记对其依赖项执行相同操作)。< / p>
无关具体问题:在JSP文件中编写Java代码是一种不好的做法。阅读Roseindia.net教程也是一个非常糟糕的主意,因为它们只显示不良实践。