免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
修改JFreeChart 圖片的存放路徑
關鍵字: jfreechart api 設置 圖片存放路徑

/**

**QQ:252574345

**MSN:lele_love_lomboz@hotmail.com

*/

 

跟蹤發(fā)現(xiàn),JFreeChart會把生成的圖片,默認放在應用服務器的temp目錄下,有的時候我們是不能放在該目錄下的,需要改變這個存放路徑

發(fā)現(xiàn)jfreechart的ServletUtilities類里有

    protected static void createTempDir() {
        String tempDirName = System.getProperty("java.io.tmpdir");
        if (tempDirName == null) {
            throw new RuntimeException("應用服務器目錄下不存在temp目錄或該目錄無法創(chuàng)建");
        }

        // create the temporary directory if it doesn't exist
        File tempDir = new File(tempDirName);
        if (!tempDir.exists()) {
            tempDir.mkdirs();
        }
    }

該方法創(chuàng)建了默認的圖片存放路徑

在該類的saveChartAsPNG() 和saveChartAsJPEG () 里被調用,產生圖形,因此我們的思路就是將ServletUtilities的saveChartAsPNG() 和saveChartAsJPEG () 這2個方法改造成自己定義的方法

修改前源文件如下:

    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();

    }

 

修改后如下:

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

//從application中讀取出臨時文件目錄,我事先已經(jīng)在系統(tǒng)啟動時,創(chuàng)建了目錄
     
       File tempDr=(File)session.getServletContext().getAttribute("tempDirectory");

      
      
        if (chart == null) {
            throw new IllegalArgumentException("chart 對象為空");  
        }
       
        UIServletUtilities.createTempDir();
        String prefix = UIServletUtilities.tempFilePrefix;
        if (session == null) {
            prefix = UIServletUtilities.tempOneTimeFilePrefix;  
        }
        File tempFile = File.createTempFile(prefix, ".jpeg", tempDr);
        ChartUtilities.saveChartAsJPEG(tempFile, chart, width, height, info);
        if (session != null) {
         UIServletUtilities.registerChartForDeletion(tempFile, session);
        }
        return tempFile.getName();

    }

 

接下來就可以使用

String filename = ServletUtilities.saveChartAsJPEG(chart, 800, 600, info, session);
String graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename;

來生成圖形了

本站僅提供存儲服務,所有內容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
JfreeChart學習總結 -花香蝶自來-學無止境 -JavaEye技術社區(qū)
用JFreeChart 輸出報表
JfreeChart學習
SSO(單點登錄)實施中遇到的幾個問題
狀態(tài)管理cookie和session
httpservletrequest 對象詳解
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服