Java 如何在不缓存spring的情况下将数据流式传输到浏览器
我已经使用Spring编写了下面的代码,在执行时将数据打印到浏览器中Java 如何在不缓存spring的情况下将数据流式传输到浏览器,java,spring,servlet-3.0,Java,Spring,Servlet 3.0,我已经使用Spring编写了下面的代码,在执行时将数据打印到浏览器中 @RequestMapping(value = "/", method = RequestMethod.GET) @ResponseBody public void get(HttpServletResponse res) throws IOException, InterruptedException { res.setHeader("CacheControl", "no-cache");
@RequestMapping(value = "/", method = RequestMethod.GET)
@ResponseBody
public void get(HttpServletResponse res) throws IOException, InterruptedException {
res.setHeader("CacheControl", "no-cache");
for (int i = 0; i <= 5; i++) {
res.getWriter().write(UUID.randomUUID().toString());
Thread.sleep(1000);
}
}
@RequestMapping(value=“/”,method=RequestMethod.GET)
@应答器
公共void get(HttpServletResponse res)抛出IOException、InterruptedException{
res.setHeader(“缓存控制”、“无缓存”);
对于(int i=0;i要实现此功能,您必须查看web套接字。这是一个基于TCP的协议。我认为这是不可能的。您必须以1000毫秒的间隔从前端生成五个请求,并且必须从后端代码中删除此for循环。@Ahmad.Masood处理时间无法预测,因此我希望将服务器控制台流式传输到浏览器根据我所知,我认为这是不可能的。HTTP不以这种方式工作。您将需要从前端连续获取它。