IllegalStateException:AsyncContext.startAsync(req,res)不支持
我创建了一个 servlet 3.0 来探索异步请求处理:
@WebServlet(name="MyTest", urlPatterns={"/MyTest"}, asyncSupported=true)
public class MyTest extends HttpServlet {
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
AsyncContext tmp = req.startAsync(req, res);
...
}
}
但是当调用 .startAsync(...)
时,我收到一个 IllegalStateException
。我知道 Javadoc 提到了该异常,但我确实显式启用了异步(参见 WebServlet
注释)。我使用的是 NetBeans 附带的 Tomcat 7.0.11.0。
我可以确认 req.isAsyncSupported()
返回 false。我做错了什么?我还需要做什么才能启用异步处理?
编辑:
我尝试实现以下示例并得到相同的结果问题。
I have created a servlet 3.0 to explore asynchronous request processing:
@WebServlet(name="MyTest", urlPatterns={"/MyTest"}, asyncSupported=true)
public class MyTest extends HttpServlet {
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
AsyncContext tmp = req.startAsync(req, res);
...
}
}
but I get an IllegalStateException
when .startAsync(...)
is called. I know the Javadoc mentions that exception, but I did explicitly enable async (c.f. WebServlet
annotation). I am using Tomcat 7.0.11.0 delivered with NetBeans.
I could confirm that req.isAsyncSupported()
is returning false. What am I doing wrong? What more do I need to do to enable async processing?
EDIT:
I tried to implement the following example and got the same issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我检查了 Tomcat 的代码,发现 asyncSupported 变量必须显式设置为 true。这就是为什么您会得到
req.isAsyncSupported() == false
。您可以尝试通过以下方法之一将 HttpServletRequest 对象中的 async 属性设置为 true。
或
希望有帮助。
I checked out Tomcat's code and saw that the asyncSupported variable has to be explicitly set to true. That's why you are getting
req.isAsyncSupported() == false
.You could try to set the async attribute in the HttpServletRequest object to true by one of the following methods.
or
Hope it helps.
请检查您是否有任何未启用支持异步的请求过滤器。您可以(暂时)删除过滤器或将其标记为支持异步。
Please check if you have any request filter which is not enabled to support async. Either you can remove the filter (temporarily) or mark it to support async.