JSP 中的 json 对象

发布于 2024-12-23 01:41:12 字数 2370 浏览 6 评论 0原文

我导入了 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)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

耀眼的星火 2024-12-30 01:41:12

这只是说明 web 应用程序的运行时类路径中缺少提到的类。您需要下载并删除包含net.sf.json<类的JAR文件/code> 包位于 /WEB-INF/lib 文件夹中(如果需要,不要忘记对其依赖项执行相同的操作)。


与具体问题无关:在 JSP 文件中编写 Java 代码是一种糟糕的做法。阅读 Roseindia.net 教程也是一个非常糟糕的主意,因为它们只展示了不好的做法。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文