1
我刚刚将org.json
库导入到我的Dynamic Web Project。作为服务器,我使用Tomcat
。当我尝试运行该应用程序时,出现此错误:java.lang.NoClassDefFoundError: org/json/JSONObject
。这是我收到的错误代码:java.lang.NoClassDefFoundError使用org.json库
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String pathInfo = request.getPathInfo();
if(pathInfo != null){
String newPathInfo = pathInfo.substring(1);
System.out.println("--> " + pathInfo);
System.out.println("--> " + newPathInfo);
System.out.println("parameter --> " + request.getParameter("format"));
String format = request.getParameter("format");
if(format != null){
if(format.equals("json")){
System.out.println("Preparing JSON reply...");
response.setContentType("text/json");
JSONObject obj = new JSONObject();
obj.put("salutation", lang.get(newPathInfo));
response.getWriter().write(obj.toString());
System.out.println("--> "+obj.toString());
}
}
}
具体来说,这就是我得到了错误的行:
obj.put("salutation", lang.get(newPathInfo));
有什么我失踪?
谢谢!
的JSON库... –
听起来像是你错过了“包括在类路径中图书馆”,但你还没有告诉我们什么你在做... –
Your'e缺少org.json jar作为你的项目的依赖项。你需要将它添加到你的类路径中。 –