我使用的是jetty的嵌入式版本。我注意到以下几点:
在处理程序方法中,如果我想直接响应 HTTP OK 响应,然后 hibernate x 秒,则处理程序执行相反的操作。这正常吗?
句柄函数如下:
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/html;charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);
baseRequest.setHandled(true);
response.getWriter().println("OK");
Thread.sleep(10000);
}
这个 SCSS 睡了 10 秒然后返回响应,为什么会发生这种情况?
最佳答案
您需要调用
response.flushBuffer();
在线程 hibernate 之前。
来自此方法的 JavaDoc:
Forces any content in the buffer to be written to the client. A call to this method automatically commits the response, meaning the status code and headers will be written.
关于java - 嵌入式 jetty 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9981313/