生成图像并在JSP中显示它以及其他内容 [英] Generate image and display it inside JSP along with other content
问题描述
我正在使用JFreeChart根据用户输入生成动态图表。我有一个带有一些文本框和组合框的JSP,用户进行输入并提交它,并且Action处理它,生成图表的图像。我需要在与文本框/组合框下面相同的JSP上显示此图像。
I'm using JFreeChart to generate a dynamic chart depending on the user input. I have a JSP with some textbox and combobox, the user makes the input and submits it, and the Action process it, generating an image of a chart. I need to display this image on the same JSP as before, below the textbox/combobox.
如果我使用 response.setContentType(image / jpeg);
等...然后我得到一个单独包含图像的页面。我想将图像保存到文件然后使用< img>
访问它,但我不确定它是否可行(需要将其保存到WebContent和我可能无法一直访问它?)。
If I use response.setContentType("image/jpeg");
etc... then I get a page with the image alone. I thought of saving the image to a file and then access it with <img >
, but I'm not sure that will work (need to save it to WebContent and I may not be able to access it always?).
有没有办法以某种方式缓存图像,然后通过< img>
还是什么?也许JFreeChart有一个简单的方法来做我想做的事情?
Is there a way to somehow cache the image and then access it inside the JSP through an <img>
or something? Maybe JFreeChart has an easy way to do what I want?
如果重要的话,我也在我的webapp上使用struts和spring。
If it matters, I'm also using struts and spring on my webapp.
提前致谢。
推荐答案
我没试过,但你可能会看一下< a href =http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/imagemap/package-summary.html =nofollow noreferrer> org.jfree .chart.imagemap
以及来自 org.jfree.chart.urls
。 此处说明了实现 PieURLGenerator
的概要。
I've not tried it, but you might look into org.jfree.chart.imagemap
and a suitable URL generator from org.jfree.chart.urls
. An outline of implementing a PieURLGenerator
is illustrated here.
这篇关于生成图像并在JSP中显示它以及其他内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!