servlet:
1 public void service(HttpServletRequest request, HttpServletResponse response) 2 throws ServletException, IOException { 3 4 response.setContentType("text/html"); 5 response.setCharacterEncoding("utf-8"); 6 7 IBllFrame interfaceOfBllFrame=new BllFrame(); 8 JSONArray json = null; 9 10 List<HashMap<String, Object>> result=interfaceOfBllFrame.GetStationPlace(); 11 System.out.println("GetStationPlace:" + result.get(1).toString()); 12 try { 13 System.out.println("haha begin:" + json); 14 15 json=new JSONArray().fromObject(result);//上述錯誤出現在此句 16 System.out.println("haha success:" + json); 17 } 18 catch (Exception e){ 19 e.printStackTrace(); 20 } 21 22 System.out.println("Servlet---StationPlace"+json); 23 PrintWriter out = response.getWriter(); 24 out.println(json); 25 out.flush(); 26 out.close(); 27 }
控制器中輸出結果如下:
下面為上圖中的信息:
GetStationPlace:{StationId=10002, Stationlon=29.90592, Stationlat=121.525976}
haha begin:null
二月 29, 2016 10:37:46 上午 org.apache.catalina.core.StandardWrapperValve invoke
嚴重: Servlet.service() for servlet [GetStationPlaceServlet] in context with path [/BicycleDataSystem] threw exception [Servlet execution threw an exception] with root cause
java.lang.ClassNotFoundException: net.sf.json.JSONArray
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1722)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1573)
原先commons-beanutils.jar 、commons-collections.jar、commons-lang.jar、 commons-logging.jar、ezmorph.jar、json-lib.jar這些包放在lib-》json文件夾下如下:
後來commons-beanutils.jar 、commons-collections.jar、commons-lang.jar、 commons-logging.jar、ezmorph.jar、json-lib.jar直接放到lib文件夾下,如下:
注意:就是說將commons-beanutils.jar 、commons-collections.jar、commons-lang.jar、 commons-logging.jar、ezmorph.jar、json-lib.jar這些包一定要直接放在lib文件夾下,否則會出現org.apache.catalina.core.StandardWrapperValve invoke錯誤。
JSONArray().fromObject需要如下jar包:commons-beanutils.jar 、commons-collections.jar、commons-lang.jar、 commons-logging.jar、ezmorph.jar、json-lib.jar
下載地址:http://pan.baidu.com/s/1pJUmBQN
相關文獻:http://greenboy1.iteye.com/blog/1046125