一尘不染

为什么在路径为[/ ABC]的上下文中,用于Servlet [XYZ]的Servlet.service()抛出异常

tomcat

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

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

        }
    }

阅读 2908

收藏
2020-06-16

共1个答案

一尘不染

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

它似乎未正确配置到应用程序中。如果它在web.xml中的应用程序appart中使用上下文xml,则无论如何都要进行检查,并且尤其要在web.xml中正确配置Servlet
XYZ,如果它在lib的.jar中,则应该检查XYZ。 jar将需要在web.xml中作为资源命名,并且服务器将需要重新启动。关于它说找不到servlet。

2020-06-16