3

我无法弄清楚为什么会收到此错误。我检查并重新检查了我的代码似乎没有发现任何错误。

16 Jul, 2012 3:21:25 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [XYZ] in context with path [/ABC] threw exception
java.lang.NullPointerException
    at com.mnp.abc.xyz.doPost(XYZ.java:116)
    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.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

XYZ servlet 的 doPost 方法

@Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        StringBuilder sb = new StringBuilder();

        InputStream rin = request.getInputStream();
        InputStream gzipStream = new GZIPInputStream(rin);
        Reader decoder = new InputStreamReader(gzipStream, "UTF-8");
        BufferedReader br = new BufferedReader(decoder);

        String str;

        // retrieve JOSNArray send to Servlet
        while ((str = br.readLine()) != null) {
            sb.append(str);
        }
        JSONArray jsonArray = null;
        try {
            jsonArray = new JSONArray(sb.toString());
        } catch (JSONException e) {
            System.out.println("Error parsing JSON");
        }
        System.out.println("json object: " + jsonArray.toString());


        // parse JSONArray and obtain ContactArray
        ArrayList<Contact> contactArray = null;
        try {
            contactArray = frmJSONArrayToContactArray(jsonArray);
        } catch (JSONException e1) {
            System.out.println(TAG + " frmJSONArrayToContactArray Failed");
        }
        // connect JDBC with MySQL server
        Context initContext;
        Connection connection;
        DataSource datasource;
        Statement statement;
        ResultSet rs = null;
        try {
            initContext = new InitialContext();
            Context envContext = (Context) initContext.lookup("java:/comp/env");
            datasource = (DataSource) envContext.lookup("jdbc/bolsms");

            // load Connector/J
            connection = datasource.getConnection();
            statement = connection.createStatement();
            // get query String
            Iterator<Contact> itetor = contactArray.iterator();
            boolean greatPeopleBoo = false;
            while (itetor.hasNext()) {
                ***Contact contact = itetor.next();***
                ....
                ....
                .... 
            }
            rs.close();
            statement.close();
            connection.close();
        } catch (NamingException ex) {
            Logger.getLogger(MarkGreatPeopleFromContact.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException e) {
            for (Throwable t : e) {
                System.out.println(t.getMessage());
            }
        }

        /*
         * send contactArray back to Android Client
         */

        }
    }
4

1 回答 1

5

org.apache.catalina.core.StandardWrapperValve 调用 SEVERE: Servlet.service() for servlet [XYZ] 在上下文中与路径 [/ABC]

它似乎未正确配置到应用程序中。如果它在来自 web.xml 的应用程序中使用上下文 xml,那么明智的做法是检查两者并确保在 web.xml 中正确配置了 servlet XYZ,尤其是如果它位于 lib 中的 .jar 中,那么 . jar 需要在 web.xml 中命名为资源,并且需要重新启动服务器。它说它找不到servlet。

于 2012-07-15T22:53:54.877 回答