Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在不缓存spring的情况下将数据流式传输到浏览器_Java_Spring_Servlet 3.0 - Fatal编程技术网

Java 如何在不缓存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");

我已经使用Spring编写了下面的代码,在执行时将数据打印到浏览器中

@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不以这种方式工作。您将需要从前端连续获取它。