如何在一个 OutputStream 中使用多个
我需要在网格布局中的 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);
}
那么,有没有一种方法可以确保在启动下一个操作之前完成一个操作?
提前致谢!
I need to show four charts on a grails page in a grid layout with positions 11, 12, 21 and 22. Each chart is build with a code similar to:
<img src="${createLink(controller:'paretoChart', action:'buildParetoChart11')}"/>
The code for the chart building action is:
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
}
The Java p11.paretoPlot(out, idPOvalue) returns a BufferedImage of the chart inside the OutputStream, but it only works for one chart. The other three charts vary on the the order on each all pour actions are called.
PlotService was written by me, yes. In this implementation, I'm passing the OutputStream out I got from response.outputStream and the String idPOvalue to the Java method. plotPareto's implementation is as follows:
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);
}
So, is there a way to make sure one action is completed before firing up the next one?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每个获取图像的请求都由浏览器异步处理。每个请求都在服务器上自己的线程中运行。使用 img 标签,浏览器控制 GET 请求来获取图像,因此我认为您不能轻松保证顺序,也不应该这样做。
您看到任何错误吗?
我会查看 firebug 或等效输出以查看浏览器是否出现错误。对于任何图像请求。
我还会尝试将调试器连接到您的服务器。
PlotService 是你写的吗?您需要确保它是线程安全的。
另外,我没有看到您读取任何参数,每个图像是否有单独的操作?
each request to get an image is handled asynchronously by the browser. Each request runs in its own thread on the server. With img tags, the browser controls the GET requests to get the images, so I don't think you can easily guarantee the order, and nor should you have to.
Are you seeing any errors?
I would look at the firebug or equivalent output to see if the browser is getting an error. for any of the image requests.
I would also try attaching a debugger to your server.
Did you write the PlotService? You need to make sure it is thread safe.
Also, I dont see you reading any params, is there a separate action for each image?