要回答我自己的问题:
Does the doGet method send the response to the client once themethod is finished executing?
是的,当doGet方法(或任何HttpServlet方法,例如:doGet,doPost等)完成执行时,会将响应发送回客户端。
If this is the case, how can I keep the connection open for a long-pollingeffect?
使用异步Servlet(但是我发现我的特定问题一定在其他地方,但是这些答案仍然与所提出的问题有关)。在ServletRequest对象上,调用startAsync方法,如下所示:
AsyncContext context = request.startAsync(request, response);
“这将通知Web容器,在请求调用结束时,它应该释放处理线程并保持连接打开,以便其他线程写入响应并结束连接。”
参考链接。
另外,我将解决方案添加到我的特定问题(客户端未收到响应)的原因是,在我的Servlet中,我没有在AsyncContext对象上调用complete方法:
asyncContext.complete();



