【问题标题】:How to use multiple with one OutputStream如何将多个与一个 OutputStream 一起使用
【发布时间】:2011-05-21 16:53:18
【问题描述】:

我需要在网格布局中的 grails 页面上显示四个图表,位置分别为 11、12、21 和 22。每个图表的构建代码类似于:

<img src="${createLink(controller:'paretoChart', action:'buildParetoChart11')}"/>

图表构建动作的代码是:

    def buildParetoChart11 = {
        def PlotService p11 = PlotService.getInstance()

        def poList = paretoChartService.getParetoidPO()
        def listCounter = 0 

        def idPO = poList[listCounter]
        idPO.toString()
        def String idPOvalue = idPO

        def out = response.outputStream

        out = p11.paretoPlot(out, idPOvalue)
        response.setContentType("image/jpg")
        session["idPOList11"] = poList
}

Java p11.paretoPlot(out, idPOvalue) 在 OutputStream 中返回图表的 BufferedImage,但它仅适用于一个图表。其他三个图表的调用顺序各不相同。

PlotService 是我写的,是的。在这个实现中,我将从 response.outputStream 得到的 OutputStream 和 String idPOvalue 传递给 Java 方法。 plotPareto的实现如下:

public OutputStream paretoPlot(OutputStream out, String po) throws IOException {
    chart = buildParetoChart(po);// here the chart is actually built
    bufferedImage = chart.createBufferedImage(350, 275);
    ChartUtilities.writeBufferedImageAsJPEG(out, bufferedImage);
}

那么,有没有办法确保在启动下一个动作之前完成一个动作?

提前致谢!

【问题讨论】:

    标签: grails jfreechart controllers outputstream


    【解决方案1】:

    每个获取图像的请求都由浏览器异步处理。每个请求都在服务器上自己的线程中运行。有了img标签,浏览器控制GET请求获取图片,所以我认为你不能轻易保证顺序,也不应该这样做。

    您是否发现任何错误?

    我会查看 firebug 或等效输出以查看浏览器是否出现错误。对于任何图像请求。

    我也会尝试将调试器附加到您的服务器。

    您是否编写了 PlotService?您需要确保它是线程安全的。

    另外,我没有看到您阅读任何参数,每个图像是否有单独的操作?

    【讨论】:

    • 您可能还想尝试刷新输出流。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-04
    • 1970-01-01
    • 2014-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-30
    相关资源
    最近更新 更多