我正在使用Simple XML API来序列化和反序列化从Android应用程序发送到servlet的XML数据。 反序列化在Android应用程序上正常工作。但是当在servlet上使用相同的代码时,我收到以下错误:
SEVERE: Servlet.service() for servlet [servlettest.ServletTest] in context with path [/test] threw exception [Servlet execution threw an exception] with root cause
java.lang.ClassNotFoundException: org.simpleframework.xml.Serializer
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
at servlettest.ServletTest.doPost(ServletTest.java:104)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
重点是java.lang.ClassNotFoundException: org.simpleframework.xml.Serializer
我已确保jar文件已在Eclipse中导入。已在“属性”窗口的“订购和导出”选项卡下选中标记。
这是在Android上运行良好但在servlet上失败的代码:
Serializer serializer = new Persister();
File source = new File("/home/kk/workspace/testfile.xml");
Reg_info_xml parse_xml = serializer.read(Reg_info_xml.class, source);
String name = parse_xml.getUser_name();
System.out.print(name);
答案 0 :(得分:1)
该类不在服务器类路径中,因此将jar放在项目的WEB-INF / lib文件夹中