F
fabien.moquet
Hello,
I am using a Servlet that generates a PNG image using JFreeChart on a
Tomcat 6.0 server.
I would like to test the servlet but in don't know how to invoke it
from my brower. I tried to open the URL http://localhost:8080/myapp/ServletBarChart
but Tomcat displays an error saying that the file could not be found.
Here is my servlet file :
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.jfree.data.*;
import org.jfree.data.category.*;
public class ServletBarChart extends HttpServlet {
protected void service(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(120000.0, "Produit 1", "2000");
dataset.addValue(550000.0, "Produit 1", "2001");
dataset.addValue(180000.0, "Produit 1", "2002");
dataset.addValue(270000.0, "Produit 2", "2000");
dataset.addValue(600000.0, "Produit 2", "2001");
dataset.addValue(230000.0, "Produit 2", "2002");
dataset.addValue(90000.0, "Produit 3", "2000");
dataset.addValue(450000.0, "Produit 3", "2001");
dataset.addValue(170000.0, "Produit 3", "2002");
JFreeChart barChart = ChartFactory.createBarChart("Evolution des
ventes", "",
"Unite vendue", dataset, PlotOrientation.VERTICAL, true, true,
false);
OutputStream out = response.getOutputStream();
response.setContentType("image/png");
ChartUtilities.writeChartAsPNG(out, barChart, 400, 300);
}
}
What am I doing wrong ?
Fabzy
I am using a Servlet that generates a PNG image using JFreeChart on a
Tomcat 6.0 server.
I would like to test the servlet but in don't know how to invoke it
from my brower. I tried to open the URL http://localhost:8080/myapp/ServletBarChart
but Tomcat displays an error saying that the file could not be found.
Here is my servlet file :
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.jfree.data.*;
import org.jfree.data.category.*;
public class ServletBarChart extends HttpServlet {
protected void service(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(120000.0, "Produit 1", "2000");
dataset.addValue(550000.0, "Produit 1", "2001");
dataset.addValue(180000.0, "Produit 1", "2002");
dataset.addValue(270000.0, "Produit 2", "2000");
dataset.addValue(600000.0, "Produit 2", "2001");
dataset.addValue(230000.0, "Produit 2", "2002");
dataset.addValue(90000.0, "Produit 3", "2000");
dataset.addValue(450000.0, "Produit 3", "2001");
dataset.addValue(170000.0, "Produit 3", "2002");
JFreeChart barChart = ChartFactory.createBarChart("Evolution des
ventes", "",
"Unite vendue", dataset, PlotOrientation.VERTICAL, true, true,
false);
OutputStream out = response.getOutputStream();
response.setContentType("image/png");
ChartUtilities.writeChartAsPNG(out, barChart, 400, 300);
}
}
What am I doing wrong ?
Fabzy