9.2.2  Example of creating a image file by the server side 
The second example shows a JSP listing of how to create the graph, encode it to a JPEG image file and 
provide a link to the file. The example is much the same as in chapter 9.2.1. 
 
<% 
  response.reset(); 
/* Init the chart object and set it's size */ 
  com.klg.jclass.chart.beans.SimpleChart chart = new 
com.klg.jclass.chart.beans.SimpleChart(); 
  chart.setSize(new java.awt.Dimension(500,300)); 
/* Fetch the graph data using a XfijFinder component. The graph will show 
lengths of lab test results (field number  6  in file  80001 ) in a simple plot 
graph connected with lines. */ 
  xfij.core.XfijFinder finder = new xfij.core.XfijFinder(); 
  finder.setFileNumber(new xfij.editor.FileNumber("80001")); 
  finder.setWRPCBroker(laboratoriotutkimusBean.getBroker()); 
  finder.setFields(new String[] { "6" }); 
  String[] results = finder.getList(); 
/* Create a TableModel that is used as data source by the graph component and 
create the actual graph image. */
  javax.swing.table.TableModel model = 
xfij.util.ChartUtil.ResultsToTableModel(results, false); 
  chart.setSwingDataModel(model); 
  chart.setXAxisTitleText("Record number"); 
  chart.setYAxisTitleText("The length of result"); 
  chart.repaint(); 
/* Save the image into a file  testImage.png . The session id string is added to 
the file name, because we need to provide access for many clients (sessions) at 
same time */ 
  java.io.File file = new 
java.io.File(application.getRealPath("testImage"+session.getId()+".png")); 
  xfij.util.ChartUtil.encode(chart.serverSnapshot(), "PNG", new 
java.io.FileOutputStream(file)); 
%> 
/* Provide the image to the client browser */ 
 
The downside of this technique is that the images must be deleted from the server by the application or they 
will remain there. 
33 






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

servlets web hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Jsp Web Hosting Cheapest Web Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved