【问题标题】:<async-supported> Element in web.xml Doesn't Seem to Workweb.xml 中的 <async-supported> 元素似乎不起作用
【发布时间】:2017-08-27 17:07:34
【问题描述】:

我正在尝试在 Jetty 中设置 servlet,并希望尝试异步功能,结果却收到以下错误:

java.lang.IllegalStateException: !asyncSupported: main.AsynchronousServlet@6d39e108==main.AsynchronousServlet,jsp=null,order=-1,inst=true
    at org.eclipse.jetty.server.Request.startAsync(Request.java:2232)
    at...

据我了解,我需要在 web.xml 中添加一个元素(我不熟悉的另一个概念)设置支持异步,所以我这样做了:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" 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>AsynchronousServlet</servlet-name>
    <servlet-class>main.AsynchronousServlet</servlet-class>
    <async-supported>true</async-supported>
  </servlet>
  <servlet-mapping>
    <servlet-name>AsynchronousServlet</servlet-name>
    <url-pattern>/AsynchronousServlet/*</url-pattern>
  </servlet-mapping>
</web-app>

但是,我仍然遇到同样的错误。我没有过滤器,所以我发现的其他一些答案不适用,而且我知道 web.xml 位于正确的位置,因为如果我拼错了类名,我会得到一个不同的错误。 有人会帮助我并告诉我我做错了什么吗?我正在使用 jetty-9.4.3.v20170317

【问题讨论】:

  • 什么版本的码头?
  • jetty-9.4.3.v20170317
  • 你有过滤器在玩吗?或AsynchronousServlet上声明的注释?

标签: java xml asynchronous jetty web.xml


【解决方案1】:

原来是下面这行:

@WebServlet("/SynchronousServlet")

这里不能使用。好像和web.xml有冲突

【讨论】:

    猜你喜欢
    • 2016-08-12
    • 2015-12-24
    • 1970-01-01
    • 1970-01-01
    • 2019-04-20
    • 1970-01-01
    • 2014-11-30
    • 2020-11-18
    • 1970-01-01
    相关资源
    最近更新 更多