我有示例项目StockWatcher使用requestbuilder与servlet进行通信(本例).我想让servlet异步.我在doGet方法中添加了以下行:
final AsyncContext ac = request.startAsync();
ac.setTimeout(1 * 60 * 1000);
ac.addListener(new AsyncListener() {
@Override
public void onError(AsyncEvent arg0) throws IOException {
System.out.println("onError");
}
public void onComplete(AsyncEvent event) throws IOException {
System.out.println("onComplete");
queue.remove(ac);
}
public void onTimeout(AsyncEvent event) throws IOException {
System.out.println("onTimeout");
queue.remove(ac);
}
@Override
public void onStartAsync(AsyncEvent arg0) throws IOException {
System.out.println("onStartAsync");
}
});
queue.add(ac);
Run Code Online (Sandbox Code Playgroud)
添加了异步注释:@WebServlet(asyncSupported=true)
并使用以下命令更改了doGet方法的其余部分:
PrintWriter out = ac.getResponse().getWriter();
out.println("Something");
out.flush();
Run Code Online (Sandbox Code Playgroud)
现在没有任何回报.我错了什么?必须在客户端改变一些东西?Glassfish 3没有显示任何错误.