0

我正在尝试使用 POST 方法在两个 servlet 之间进行通信。在本地,每件事都有效。但是,当我在真实服务器上部署我的 servlet 时,我遇到了一个异常。请问我该如何解决?

在我的第一个 servlet1 中,我有:

try {
        gwtServlet = new URL("http://dbapp-test-env.elasticbeanstalk.com/Bdconnection");
        HttpURLConnection servletConnection = (HttpURLConnection) gwtServlet.openConnection();
        servletConnection.setRequestMethod("POST");
        servletConnection.setDoOutput(true);   
        ObjectOutputStream objOut = new ObjectOutputStream(servletConnection.getOutputStream());
        objOut.writeObject(obj);
        objOut.flush();
        objOut.close();
        code = servletConnection.getResponseCode();
        str = servletConnection.getErrorStream();
        servletConnection.getInputStream();

} catch (Exception e) {
            response.getWriter().println("Exception : "+getStackTrace(e));
            response.getWriter().println("Error in catch of servlet 1: "+getStringFromInputStream(str));
            e.printStackTrace();
        }

如果你注意到了,我也会在catch.

我的第二个 servlet 位于http://dbapp-test-env.elasticbeanstalk.com/Bdconnection. 我在其中doPost

try {
            ObjectInputStream objIn = new ObjectInputStream(request.getInputStream());
            SimObjectResult obj = (SimObjectResult) objIn.readObject();

        } catch (Throwable e) {
            printwriter.print(getStackTrace(e));
        }

在执行期间,我在servelt 1中遇到了这个异常:

    Exception : java.io.IOException: Server returned HTTP response code: 500 for URL: http://dbapp-test-env.elasticbeanstalk.com/Bdconnection
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1890)
    at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1885)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1884)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1457)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
    at org.simulation.Simulation.doPost(Simulation.java:92)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    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:212)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:676)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: Server returned HTTP response code: 500 for URL: http://dbapplicationcoapssample-test-env.elasticbeanstalk.com/Bdconnection
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1840)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
    at org.simulation.Simulation.doPost(Simulation.java:90)
    ... 24 more

而内部服务器除外

Error in catch of servlet 1: java.lang.ClassNotFoundException: org.simulation.SimObjectResult   at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)  
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)  
    at java.lang.Class.forName0(Native Method)  
    at java.lang.Class.forName(Class.java:278)  
    at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:625)   
    at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1612)  
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1517) 
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)    
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)   
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370) 
    at org.stockage.Bdconnection.doPost(Bdconnection.java:78)   
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:650) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)    
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)    
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)   
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)    
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)    
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)  
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)  
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)   
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)    
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)    
    at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:683)  
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)    
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)    
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)  
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)  
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)  
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)  
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)  
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)   
    at java.lang.Thread.run(Thread.java:745)

在我的两个 servlet 的战争应用程序中,我有SimObjectResult.class

4

1 回答 1

1

错误是这个

java.lang.ClassNotFoundException: org.simulation.SimObjectResult

检查包含该类的 jarorg.simulation.SimObjectResult是否存在于您的 Web 应用程序的类路径中。

所有其他错误都与此有关。

于 2016-01-06T11:48:52.513 回答