我想显示一个jfreechart
jsp 页面中的图表。我写的代码如下 -
...
<%
ChartCreator chart = new ChartCreator();
chart.createCategoryChart();
%>
<img src = "chart.jpg"/>
哪里的createCategoryChart()
方法创建所需的 jpg。它存储在 eclipse 文件夹中(我没有在文件名中添加任何路径)。
我无法在jsp页面中查看图表,但文件已创建。
我究竟做错了什么?
我建议使用 Servlet 来创建图表。
JSP主要用于呈现(View)。
创建一个 Servlet,用于创建图表并将其作为响应发回。
import javax.imageio.ImageIO;
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
OutputStream out = response.getOutputStream(); /* Get the output stream from the response object */
response.setContentType("image/png"); /* Set the HTTP Response Type */
ChartCreator chart = new ChartCreator(); // Create chart
chart.createCategoryChart();
ChartUtilities.writeChartAsPNG(out, chart, 400, 300);/* Write the data to the output stream */
}
从 JSP 调用 Servlet。
<img src="/drawChartServlet?type=myDesiredChart&width=..and other processed parameters" ..
>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)