到底哪里错了?why错了?
PrintWriter out = response.getWriter(); Result result = new Result(); result.setResult(1); List<Person> personlist = new ArrayList<Person>(); Person person = new Person(); person.setAge(24); person.setName("hehe"); person.setUrl("dgfye"); List<SchoolInfo> schoolInfolist = new ArrayList<SchoolInfo>(); SchoolInfo schoolinfo1 = new SchoolInfo(); schoolinfo1.setSchoolname("清华"); SchoolInfo schoolinfo2 = new SchoolInfo(); schoolinfo2.setSchoolname("郑大"); schoolInfolist.add(schoolinfo1); schoolInfolist.add(schoolinfo2); person.setList(schoolInfolist); personlist.add(person); Person person1 = new Person(); person1.setAge(24); person1.setName("Bean"); person1.setUrl("dgfye"); List<SchoolInfo> schoolInfolist1 = new ArrayList<SchoolInfo>(); SchoolInfo schoolinfo3 = new SchoolInfo(); schoolinfo3.setSchoolname("人大"); SchoolInfo schoolinfo4 = new SchoolInfo(); schoolinfo4.setSchoolname("北大"); schoolInfolist1.add(schoolinfo3); schoolInfolist1.add(schoolinfo4); person1.setList(schoolInfolist1); personlist.add(person1); result.setList(personlist); Gson gson = new Gson(); System.out.println(gson.toJson(result)); out.println(gson.toJson(result));
代码没报错,运行时错了,如下:
十月 20, 2015 10:27:53 上午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [bean.json.servlet.BeanJson] in context with path [/BeanJsonPro] threw exception [Servlet execution threw an exception] with root cause
java.lang.ClassNotFoundException: com.google.gson.Gson
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1320)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1173)
at bean.json.servlet.BeanJson.doPost(BeanJson.java:90)
at bean.json.servlet.BeanJson.doGet(BeanJson.java:42)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:534)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1081)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:277)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2381)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2370)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)