为什么Servlet.service()for servlet [XYZ]在路径[/ ABC]的上下文中引发了异常

时间:2012-07-15 22:38:15

标签: tomcat tomcat7 netbeans-7

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

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
         */

        }
    }

1 个答案:

答案 0 :(得分:5)

org.apache.catalina.core.StandardWrapperValve调用 严重:servlet [XYZ]的Servlet.service()与路径[/ ABC]的上下文

它似乎未正确配置到应用程序中。如果它在web.xml中的应用程序appart中使用上下文xml,那么无论如何都要检查servlet XYZ是否在web.xml中正确配置,如果它位于lib中的.jar中,那么。 jar需要在web.xml中作为资源命名,并且需要重新启动服务器。 它说它无法找到servlet。