我會建議使用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" ..
>