gpt4 book ai didi

java - Servlet 中的 JSONObject ClassNotFoundException

转载 作者:行者123 更新时间:2023-12-01 10:49:28 25 4
gpt4 key购买 nike

我想在我的 Servlet 中创建一个 JSONObject:

import org.json.JSONObject;
[...]
Map<String, String> data1 = new HashMap<String, String>();
Map<String, String> data2 = new HashMap<String, String>();
data1.put("name", "f1");
data1.put("key", "aa1");
data1.put("value", "21");
data2.put("name", "f2");
data2.put("key", "aa2");
data2.put("value", "22");

JSONObject json1 = new JSONObject(data1);

但是当我运行我的应用程序时,出现异常:

exception 
javax.servlet.ServletException: Servlet execution threw an exception

root cause
java.lang.NoClassDefFoundError: org/json/JSONObject
servlet.LoginServlet.doPost(LoginServlet.java:71)
javax.servlet.http.HttpServlet.service(HttpServlet.java:643)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)


root cause
java.lang.ClassNotFoundException: org.json.JSONObject
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
servlet.LoginServlet.doPost(LoginServlet.java:71)
javax.servlet.http.HttpServlet.service(HttpServlet.java:643)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)

我使用了以下 json 资源: https://code.google.com/p/org-json-java/downloads/list

最佳答案

Download java-json jar file and add it into class path.

For Classpath reference: Right click on project in eclipse -> Buildpath -> Configure Build path -> Java Build Path (left Pane) -> Libraries(Tab) -> Add External Jars -> Select your jar and select ok.

关于java - Servlet 中的 JSONObject ClassNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33998781/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com