gpt4 book ai didi

servlets - Servlet 3.0 异步支持不起作用

转载 作者:行者123 更新时间:2023-12-02 10:31:27 25 4
gpt4 key购买 nike

这是我的 web.xml

    <filter>
<filter-name>pollingTest</filter-name>
<filter-class>
webapp.controller.core.servlet.PollingService
</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>pollingTest</filter-name>
<url-pattern>/app/poll</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>ASYNC</dispatcher>
</filter-mapping>

这是类(class):

public class PollingService implements Filter {
Logger logger = LoggerFactory.getLogger(getClass());

@Override
public void destroy() {
logger.info("Destroy");
}

@Override
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {

logger.info("Running");
req.startAsync(req, res);
this.doFilter(req, res, chain);
return;
}

@Override
public void init(FilterConfig arg0) throws ServletException {

logger.info("Init=");
}

}

我在 glassfish 和 tomcat 7 上运行它,出现异常:

java.lang.IllegalStateException: Request is within the scope of a filter or servlet that does not support asynchronous operations
at org.apache.catalina.connector.Request.startAsync(Request.java:3657)
at org.apache.catalina.connector.Request.startAsync(Request.java:3633)
at org.apache.catalina.connector.RequestFacade.startAsync(RequestFacade.java:1053)
at javax.servlet.ServletRequestWrapper.startAsync(ServletRequestWrapper.java:450)

谁能帮我解决这个问题?非常感谢。

最佳答案

因为您的 servlet 和链中的任何其他过滤器必须具有 <async-supported>true</async-supported>在 web.xml 中。

关于servlets - Servlet 3.0 异步支持不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4104907/

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