gpt4 book ai didi

java - 处理 asyncServlet 时出现 NullPointerException

转载 作者:行者123 更新时间:2023-12-02 07:07:35 26 4
gpt4 key购买 nike

我正在关注this教程 -

当我发送这样的请求时 -

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>

第50行:executor.execute(new AsyncRequestProcessor(asyncCtx,dispatch));

最佳答案

如果第 50 行是这样:

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

那么导致 NPE 的最可能的直接原因是 executornull

如果asyncCtxdispatch是装箱的原始类型,那么您可以通过拆箱null获得NPE。然而,考虑到变量的名称,这似乎不太可能。对我来说,它们看起来像是“常规”类实例的名称。

关于java - 处理 asyncServlet 时出现 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15914118/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com