JSP/Servlet sample code for Tomcat

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
Post Reply
SDG
Newbie
Newbie
Posts: 40
Joined: Tue Apr 08, 2003 4:00 am

JSP/Servlet sample code for Tomcat

Post by SDG » Fri Jul 24, 2009 11:55 am

Hello,

Do you have any samples for Tomcat webserver? If not can I get one?

Thanks in advance,
Best,
Veeranna Ronad.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: JSP/Servlet sample code for Tomcat

Post by Narcís » Fri Jul 24, 2009 1:45 pm

Hi Veerana,

TeeChart is useable in a servlet though we don't currently have a prepared example. We'll build one to be included with a future version. In the meantime a summary on how it could be used is shown here:

Using your IDE's servlet template to create a Servlet project, modify the doGet method of the servlet file in the following way:

Code: Select all

import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.steema.teechart.Chart;
import com.steema.teechart.styles.Line;

import javax.imageio.stream.ImageOutputStream;
import javax.imageio.ImageIO;

public class TeeChartServlet extends HttpServlet {

  public void doGet(HttpServletRequest request,
                  HttpServletResponse response)
        throws IOException, ServletException
  {

    Chart chart = new Chart();
    //add Series and data fill routines here
    Line line=new Line(chart);
    line.fillSampleValues(10);
    
    OutputStream out = response.getOutputStream();
    ImageOutputStream ios = ImageIO.createImageOutputStream(out);    

    //Write Chart to imagestream
    chart.getExport().getImage().getJPEG().save(ios);        

    // Set content type
    response.setContentType("image/jpg");

    // Set content size
    response.setContentLength((int)ios.length());

    // Open the output stream
    OutputStream out = response.getOutputStream();

    ios.close();
    out.close();
  }
}
This hasn't been tested yet as we'll need to prepare a server environment to test it but the underlying principle should work ok.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply