2015-11-02 54 views
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)); 

有什麼我失蹤?
謝謝!

+0

的JSON庫... –

+1

聽起來像是你錯過了「包括在類路徑中圖書館」,但你還沒有告訴我們什麼你在做... –

+1

Your'e缺少org.json jar作爲你的項目的依賴項。你需要將它添加到你的類路徑中。 –

回答

1

我已經複製到圖書館WEB-INF/lib文件夾,它是工作

相關問題