Graph without image jsp

Asked

Viewed 58 times

3

Hello! I’m looking to generate graph by jsp

I tried to follow that tutorial

But only a little square appears in the left corner of the page when I run Filing cabinet Torta.jsp

<%  
    try{
      DefaultPieDataset data = new DefaultPieDataset();    
      while(rs.next()){
          data.setValue(rs.getString("marca"), rs.getInt("TOTAL"));
      }

      JFreeChart grafico = ChartFactory.createPieChart("Cantidad Productos", data, true, true, true);

      response.setContentType("image/JPEG");
      OutputStream sa = response.getOutputStream();

      ChartUtilities.writeChartAsJPEG(sa, grafico, 600,600 );

    }
    catch(Exception ex){
    }
%>

Filing cabinet conexion.jsp

<%
     Class.forName("com.mysql.jdbc.Driver").newInstance();
     Connection cn = DriverManager.getConnection("jdbc:mysql://localhost:3306/producto","root","123");
     Statement cmd= cn.createStatement();
     String sql = "SELECT MARCA, SUM(CANTIDAD) AS TOTAL FROM   PRODUCTO_CANTIDAD GROUP BY MARCA";
     ResultSet rs = cmd.executeQuery(sql);
%>

Screenshot of how the chart appears:

inserir a descrição da imagem aqui

Thank you in advance.

1 answer

0


Some possibilities:

  1. How you are referencing this image on the page?
  2. You tried to run this query in the database to see if it returns data?
  3. Tried to put ex.printStackTrace() in the catch to see if there is no error in the execution?
    1. How are you referencing this image on the page? Have you tried running this query in the database to see if it returns data? Tried to put an ex.printStackTrace() in the catch to see if there is no error in the execution?
  • 1How are you referencing this image on the page? The Code is only this 2. Have you tried running this query in the database to see if it returns data? Yes. Returns data 3. Tried to put an ex.printStackTrace() in the catch to see if there is no error in the execution? I will try now

  • on the Chrome console it appears like this: net::ERR_INCOMPLETE_CHUNKED_ENCODING

  • 1

    Try to close Outputstream ( sa.close() ), if it does not work, call the flush before closing ( sa.flush() )... It seems that the browser does not receive the end of the file...

  • That’s it! It worked with sa.close(); !

  • That’s right! It was right! That’s right! I added sa.close(); and it worked. Thank you very much!

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.