Servlet 中的 JSONObject ClassNotFoundException
JSONObject ClassNotFoundException in Servlet
我想在我的 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.
我想在我的 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.