IllegalStateException异常:不支持AsyncContext.startAsync(REQ,RES) [英] IllegalStateException: Not supported on AsyncContext.startAsync(req, res)
问题描述
我已经创建了一个servlet 3.0探索异步请求处理:
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);
...
}
}
但我得到一个 IllegalStateException异常
在 .startAsync(...)
被调用。我知道的Javadoc提到的例外,但我没有明确地启用异步(参考 WebServlet
注释)。我使用Tomcat 7.0.11.0与NetBeans交付。
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.
我可以证实, req.isAsyncSupported()
终止返回false。我究竟做错了什么?更重要的是,我需要做的,使异步处理?
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?
编辑:
我试图实施以下例如并得到了相同的问题。
I tried to implement the following example and got the same issue.
推荐答案
我检查了Tomcat的code,只见那asyncSupported变量必须显式地设置为true。这就是为什么你得到 req.isAsyncSupported()==假
。
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
.
您可以尝试通过以下方法之一设置在HttpServletRequest对象为true异步属性。
You could try to set the async attribute in the HttpServletRequest object to true by one of the following methods.
req.setAttribute("org.apache.catalina.ASYNC_SUPPORTED", true);
或
((org.apache.catalina.connector.Request)req).setAsyncSupported(true);
希望它帮助。
这篇关于IllegalStateException异常:不支持AsyncContext.startAsync(REQ,RES)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!