JFreeChart Servlet / JSP ExamplesThe following examples show how to use some of the new facilities in JFreeChart (since version 0.9.3) that are designed for use in a servlet / JSP environment. The new facilities are:
These examples make particular use of classes in the following packages:
Refer to the JavaDoc for specifics of the API.
All the examples use the same dataset which is hit data from a fictious web site over the month of August 2002 categorized into areas of the site. The hit data is all hard coded in the WebHitDataSet class. This is to keep the setup for the examples as simple as possible. Normally I would keep data like this in a database for easier querying and updating.
There are a couple of key advantages to writing the charts to the temporary directory and then using the DisplayChart servlet to binary stream them to the client, rather than writing the charts into part of the file system that is directly accessible via HTTP.
In addition, the servlet has been written to make sure that only files from the temporary directory can be served. Frequently servlets that perform binary streaming can inadvertently open up the entire file system to someone who doesn't mind hand-typing some URLs. |