在与两个servlet通信时出现内部服务器错误

时间:2016-01-06 11:45:58

标签: java servlets post http-status-code-500

我正在尝试使用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中保留异常的痕迹。

我是位于http://dbapp-test-env.elasticbeanstalk.com/Bdconnection的第二个servlet。我有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的war应用程序中,我有SimObjectResult.class

1 个答案:

答案 0 :(得分:1)

错误就是这个

Name

检查包含类java.lang.ClassNotFoundException: org.simulation.SimObjectResult 的jar是否存在于Web应用程序的类路径中。

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