在jsp页面中显示jfreechart
我想在jsp页面中显示在jsp页面中显示jfreechart,jsp,jfreechart,Jsp,Jfreechart,我想在jsp页面中显示jfreechart图表。我已经编写了如下代码- ... <% ChartCreator chart = new ChartCreator(); chart.createCategoryChart(); %> <img src = "chart.jpg"/> 。。。 其中,createCategoryChart()方法创建所需的jpg。它存储在eclipse文件夹中(我没有在文件名中放置任何路径) 我无法在jsp页面中查看图表,但文件已创建 我做
jfreechart
图表。我已经编写了如下代码-
...
<%
ChartCreator chart = new ChartCreator();
chart.createCategoryChart();
%>
<img src = "chart.jpg"/>
。。。
其中,createCategoryChart()
方法创建所需的jpg。它存储在eclipse文件夹中(我没有在文件名中放置任何路径)
我无法在jsp页面中查看图表,但文件已创建
我做错了什么?我建议使用Servlet创建图表 JSP主要用于表示(视图) 创建一个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
我建议使用Servlet创建图表
JSP主要用于表示(视图)
创建一个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
>