3 Replies Latest reply: Jan 28, 2013 12:04 AM by r035198x RSS

    How do I send text output to a browser as the text is generated?

    649509
      Hi,

      I'm using JBoss 7.1.1.Final. I'm writing a Spring 3.1.1.RELEASE web application and have a massive amount (~5MB) of text output to send to the browser. I would like the browser to display the output as it is generated, but right now, the browser only displays everything after the servlet's doGet method completes. Here's my method …
          @RequestMapping(value = "/mymethod", method = RequestMethod.GET)
          public void refreshOrders(final HttpServletResponse response) throws IOException
          {
              execute(response, myWorker);
          }
          
          private void execute(final HttpServletResponse response,
                               final AbstractWorker worker) throws IOException
          {
              response.setBufferSize(1024);
              final Writer writer = response.getWriter();
              
              final Logger logger = Logger.getRootLogger();
              final WriterAppender appender = new WriterAppender(new PatternLayout("%d{ISO8601} %p - %m%n"),writer);
              appender.setName("CONSOLE_APPENDER");
              appender.setThreshold(org.apache.log4j.Level.DEBUG);
              logger.addAppender(appender);
                     
              try 
              {
                  worker.work();
              } finally {
                  logger.removeAppender("CONSOLE_APPENDER");
                  writer.flush();    
              }        
          }   // execute
      Is this possible? I set my buffer size to be 1K but that doesn't do anything. Thanks for any info, - Dave