Servlets - 单击按钮时突破循环?

时间:2017-05-23 02:11:41

标签: java servlets

我在Java Servlet类中有这个循环:

public String toHtmlString() throws IOException, DRException {
    File tempFile = Files.createTempFile("tempInvoiceHTML", "").toFile();

    Path tempDir = Files.createTempDirectory("");

    FileOutputStream fileOutputStream = new FileOutputStream(tempFile);
    JasperHtmlExporterBuilder htmlExporter = export.htmlExporter(fileOutputStream).setImagesURI("");

    htmlExporter.setOutputImagesToDir(true);
    htmlExporter.setImagesDirName(tempDir.toUri().getPath());
    htmlExporter.setUsingImagesToAlign(false);

    reportBuilder.toHtml(htmlExporter);

    String html = new String(Files.readAllBytes(Paths.get(tempFile.toURI())));

    for (Path path : Files.list(Paths.get(tempDir.toUri().getPath())).collect(Collectors.toList())) {
        String fileName = path.getFileName().toString();

        byte[] encode = Base64.encode(FileUtils.readFileToByteArray(path.toFile()));

        html = html.replaceAll(fileName, "data:image/png;base64,"+ new String(encode));
    }

    return html;
}

生成的页面如下所示:

enter image description here

每行以增量方式打印到屏幕上。如何在单击按钮时突破循环?换句话说,如果用户在第3行打印时单击“停止”,它应该会脱离循环。

PS:我想用servlet做这件事。我有充分的理由不使用JSP。

0 个答案:

没有答案
相关问题