public static String saveChartAsJPEG(JFreeChart chart, int width, 
                                         int height, HttpSession session) 
            throws IOException {

        return ServletUtilities.saveChartAsJPEG(chart, width, height, null, 
                session);
        
    }

    /**
     * Saves the chart as a JPEG format file in the temporary directory and
     * populates the <code>ChartRenderingInfo</code> object which can be used 
     * to generate an HTML image map.
     * <p>
     * SPECIAL NOTE: Please avoid using JPEG as an image format for charts,
     * it is a "lossy" format that introduces visible distortions in the
     * resulting image - use PNG instead.  In addition, note that JPEG output
     * is supported by JFreeChart only for JRE 1.4.2 or later.
     *
     * @param chart  the chart to be saved (<code>null</code> not permitted).
     * @param width  the width of the chart
     * @param height  the height of the chart
     * @param info  the ChartRenderingInfo object to be populated
     * @param session  the HttpSession of the client (if <code>null</code>, the
     *                 temporary file is marked as "one-time" and deleted by 
     *                 the {@link DisplayChart} servlet right after it is
     *                 streamed to the client).
     *
     * @return The filename of the chart saved in the temporary directory
     *
     * @throws IOException if there is a problem saving the file.
     */
    public static String saveChartAsJPEG(JFreeChart chart, int width, 
            int height, ChartRenderingInfo info, HttpSession session)
            throws IOException {

        if (chart == null) {
            throw new IllegalArgumentException("Null 'chart' argument.");   
        }
        
        ServletUtilities.createTempDir();
        String prefix = ServletUtilities.tempFilePrefix;
        if (session == null) {
            prefix = ServletUtilities.tempOneTimeFilePrefix;   
        }
        File tempFile = File.createTempFile(prefix, ".jpeg", 
                new File(System.getProperty("java.io.tmpdir")));
        ChartUtilities.saveChartAsJPEG(tempFile, chart, width, height, info);
        if (session != null) {
            ServletUtilities.registerChartForDeletion(tempFile, session);
        }
        return tempFile.getName();