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