0

我正在关注教程 -

当我这样发送请求时-

http://localhost:9090/AsyncServlet?id=99&dispatch=true&timeout=false

我越来越关注-

Apr 09, 2013 4:01:09 PM com.mycompany.mavenproject1.AsyncServlet doGet
INFO: AsyncServlet: Processing request: 99. on thread: 27:qtp2072997125-27[4/9/13 4:01 PM]
2013-04-09 16:01:09.503:WARN:oejs.ServletHandler:/AsyncServlet
java.lang.NullPointerException
    at com.mycompany.mavenproject1.AsyncServlet.doGet(AsyncServlet.java:50)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:735)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:669)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:457)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1075)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:384)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1009)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
    at org.eclipse.jetty.server.Server.handle(Server.java:368)
    at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489)
    at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:942)
    at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1004)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:640)
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
    at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
    at java.lang.Thread.run(Thread.java:722)

我只是不知道从哪里开始调试。我的 web.xml 看起来像这样-

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0"> 

<servlet>
    <servlet-name>AsyncServlet</servlet-name>
    <servlet-class>com.mycompany.mavenproject1.AsyncServlet
    </servlet-class>        
    <async-supported>true</async-supported>

</servlet>
<servlet-mapping>
    <servlet-name>AsyncServlet</servlet-name>
    <url-pattern>/AsyncServlet/*</url-pattern>
</servlet-mapping>

</web-app>

Line50: executor.execute(new AsyncRequestProcessor(asyncCtx, dispatch));

4

2 回答 2

1

唯一可能迫使 aNullPointerException从该行抛出的情况是executor对象未正确初始化。

于 2013-04-09T23:18:19.983 回答
1

如果第 50 行是这样的:

executor.execute(new AsyncRequestProcessor(asyncCtx, dispatch));

那么 NPE 最可能的直接原因executor就是null.

如果asyncCtxdispatch在哪里装箱原始类型,那么您可以从 unboxing 获得 NPE null。然而,考虑到变量的名称,这似乎不太可能。在我看来,它们就像“常规”类实例的名称。

于 2013-04-09T23:18:22.917 回答