这是我的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>
以下是这个类:
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)
谁能帮助我解决这个问题?非常感谢。
<web-app>
标签定义和命名空间)。 - Bozho