相关疑难解决方法(0)

web.xml中支持异步的目的是什么?

<servlet>
        <description>xxx</description>
        <servlet-name>xxx</servlet-name>
        <servlet-class>com.xxx.yyy</servlet-class>
        <async-supported>true</async-supported>
</servlet>
Run Code Online (Sandbox Code Playgroud)

async-supportedservlet的web.xml配置文件的目的是什么?我可以在什么情况下使用它?

java asynchronous web.xml servlets

38
推荐指数
1
解决办法
3万
查看次数

在处理请求时使用异步Servlet以及dispatch()和complete()方法的行为

我正在使用异步Servlet来处理请求,

根据Docs :( complete(),dispatch())

????????????????????????????????????????????????????????????????????????????????
? void complete()  ? Completes the asynchronous operation and closes the       ?
?                  ? response associated with this asynchronous context.       ?
?                  ? You call this method after writing to the response object ?
?                  ? inside the asynchronous context.                          ? 
????????????????????????????????????????????????????????????????????????????????
? void dispatch()  ? Dispatches the request and response objects               ?
?                  ? of this AsyncContext to the servlet container.            ?
????????????????????????????????????????????????????????????????????????????????
Run Code Online (Sandbox Code Playgroud)

我无法理解async.dispatch(),async.complete()及其工作原理.
我对此几乎没有疑问:

  1. 究竟有什么区别async.dispatch() …

java concurrency asynchronous servlets guava

10
推荐指数
1
解决办法
7313
查看次数

如何在servlet规范3中正确检测客户端断开连接?

我已经尝试写入响应,因为没有正确的断开回调:

private boolean write(byte[] output, AsyncContext context) {
    try {
        OutputStream stream  = context.getResponse().getOutputStream();
        stream.write(output);
        stream.flush();
        return true;
    } catch (IOException ex) {
        //client disconnected
        log.error(ex);
        removeAsyncContext(context);
        return false;
    }

}
Run Code Online (Sandbox Code Playgroud)

但这似乎没有诀窍.当客户端断开连接时,写入和刷新缓冲区不会引发异常.

奇怪的是,第二次尝试写入输出流时(断开连接后),写入会引发异常.它看起来像你第一次写/刷它,一些内部状态被设置为错误,没有通知.

我试过Jetty 8和Tomcat 7,我看到了同样的行为.

是否有解决方案来确定客户是否收到了该消息?我错过了什么吗?

java client asynchronous disconnect servlet-3.0

6
推荐指数
1
解决办法
3449
查看次数

AsyncContext 和 I/O 错误处理(当对等断开连接时)

我正在使用 Servlet 3.0 的javax.servlet.AsyncContext接口实现服务器发送的事件。

但是,我无法理解我应该如何处理对等断开连接等 I/O 错误。

对于给定的AsyncContext ac = request.startAsync(),我可以调用ac.getResponse().getWriter().print(something)然后ac.getResponse.getWriter().flush()它工作正常。但是,当客户端断开连接时,我不会收到错误消息——即使我附加了一个侦听器,onError也不会调用它的方法。

我用 Jetty 8 和 Tomcat 7 对它进行了测试,似乎与客户端的断开连接没有报告给应用程序。

如何检测通信错误?

tomcat comet jetty servlet-3.0 jakarta-ee

5
推荐指数
1
解决办法
1652
查看次数