To keep an image in the Server

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
jesusmgmarin
Posts: 13
Joined: Thu Apr 20, 2006 2:24 pm
Location: Spain
Contact:

To keep an image in the Server

Post by jesusmgmarin » Thu Apr 20, 2006 2:29 pm

I am using Debian + tomcat + j2sdk1.4.2_10 + jfreechar-1.0.1 ...

I have a doubt on how adding a functionality. I have a page in jsp that loads an Applet, this Applet loads a Servlet which generates a graph with JFreeChart. This works correctly, but in the Servlet I have:

Code: Select all

........
  response.setContentType("image/jpeg");
  
  OutputStream myOutStream = response.getOutputStream();
  JFreeChart myChart  = crearChart();
        
  int ancho = getParamEntero(request,"ancho",400);
  int alto = getParamEntero(request,"alto",300);
        
  ChartUtilities.writeChartAsJPEG(myOutStream,myChart,ancho,alto);
  ChartUtilities.saveChartAsJPEG(new File("/usr/local/tomcat/webapps/Usuarios/graph1.jpg"), myChart, ancho, alto);
 
  myOutStream.close();
.....
Servlet separately works correctly (it keeps the image in the Server, in the indicated directory). And the Applet also works correctamente( It loads the Servlet and shows the Servlet), but what it does not work to me it is:

Code: Select all

ChartUtilities.saveChartAsJPEG(new File("/usr/local/tomcat/webapps/Usuarios/graph1.jpg"), myChart, ancho, alto);
The image in the Server does not keep (when I do this with the Applet).


Somebody can say to me why does not keep the image?
Thanks.[/b]

angel
Posts: 899
Joined: Thu Jan 15, 2004 12:07 am
Location: Germany - Palatinate

Re: To keep an image in the Server

Post by angel » Thu Apr 20, 2006 3:00 pm

jesusmgmarin wrote:I have a page in jsp that loads an Applet, this Applet loads a Servlet which generates a graph with JFreeChart.
Sorry, but this seems to be very odd. Why do you need the Applet, when you have a server in the backend which generates the chart for you???

jesusmgmarin
Posts: 13
Joined: Thu Apr 20, 2006 2:24 pm
Location: Spain
Contact:

Post by jesusmgmarin » Thu Apr 20, 2006 3:31 pm

Hi, and thanks for write me.

I have been able to load and that the Servlet works that generates the graph, but ademas of the graph I want to show more texts in servlet.
In servlet I have (so that it shows gráfica)

Code: Select all

    response.setContentType("image/jpeg");
and I have tried to put

Code: Select all

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();

soon so that it can write using out.println("..."); but I have not obtained the form to do it.
Therefore treatment of which the applet loaded servlet in the page jsp, and this way I can add more text.

If there is form to do first that I have put, How?

Thanks!![/code]

angel
Posts: 899
Joined: Thu Jan 15, 2004 12:07 am
Location: Germany - Palatinate

Post by angel » Thu Apr 20, 2006 3:38 pm

Have you tried to generate an HTML page with the servlet? There you can put an <img> tag with the url of the chart and also include additional text.

jesusmgmarin
Posts: 13
Joined: Thu Apr 20, 2006 2:24 pm
Location: Spain
Contact:

Post by jesusmgmarin » Thu Apr 20, 2006 3:51 pm

Thanks very much.

I didn´t know that a Servlet that generates a graph could be invoked with the tag <img>

Now it runs
:wink:

Locked