<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    道非道 非常道

    勤思、謹言、慎行、厚積、薄發(fā)

    統(tǒng)計

    web

    天圓

    經(jīng)濟 政治 軍事

    鍵康

    [轉(zhuǎn)]jsp生成靜態(tài)頁程序

    package   com.r.util;  
       
      import   java.io.*;  
      import   java.util.Map;  
       
      import   org.apache.commons.logging.Log;  
      import   org.apache.commons.logging.LogFactory;  
      import   freemarker.template.*;  
       
      public   class   MakeHtmlFile   {  
       
      private   final   Log   logger   =   LogFactory.getLog(getClass());  
       
      private   Configuration   freemarkerCfg   =   null;  
       
      private   String   templatePath   =   "";  
       
      private   String   realBuildPath   =   "";  
       
      /**  
        *    
        *   @param   realBuildPath根目錄絕對路徑  
        *   @param   templatePath模板相對路徑,不包含模板名稱  
        */  
      public   MakeHtmlFile(String   realBuildPath,   String   templatePath)   {  
      this.templatePath   =   templatePath;  
      this.realBuildPath   =   realBuildPath;  
      setTemplatePath();  
      }  
       
      /**  
        *    
        *   @param   templatePath:模板絕對路徑  
        */  
      private   void   setTemplatePath()   {  
      //   設(shè)置freemarker的參數(shù)  
      freemarkerCfg   =   new   Configuration();  
      try   {  
      File   file   =   new   File(realBuildPath+templatePath);  
      freemarkerCfg  
      .setDirectoryForTemplateLoading(file);  
      freemarkerCfg.setObjectWrapper(new   DefaultObjectWrapper());  
      freemarkerCfg.setDefaultEncoding("UTF-8");  
      }   catch   (IOException   ex)   {  
      System.out.println("No   Directory   found,please   check   you   config."n"  
      +   realBuildPath+templatePath);  
      }  
      }  
       
      /**  
        *   生成靜態(tài)文件  
        *    
        *   @param   templateFileName  
        *                         模版名稱eg:(biz/order.ftl)  
        *   @param   propMap  
        *                         用于處理模板的屬性O(shè)bject映射  
        *   @param   htmlFilePath  
        *                         要生成的靜態(tài)文件的路徑,相對設(shè)置中的根路徑,例如   "/biz/2006/5/"  
        *   @param   htmlFileName  
        *                         要生成的文件名,例如   "123.htm"  
        *   @return  
        */  
      public   boolean   buildHtml(String   templateFileName,   Map   propMap,  
      String   htmlFilePath,   String   htmlFileName)   {  
      try   {  
      Template   template   =   freemarkerCfg.getTemplate(templateFileName);  
      template.setEncoding("UTF-8");  
      //   創(chuàng)建生成文件目錄  
      creatDirs(realBuildPath,   htmlFilePath);  
      File   htmlFile   =   new   File(realBuildPath   +   htmlFilePath  
      +   htmlFileName);  
      Writer   out   =   new   BufferedWriter(new   OutputStreamWriter(  
      new   FileOutputStream(htmlFile),   "UTF-8"));  
      template.process(propMap,   out);  
      out.flush();  
      return   true;  
      }   catch   (TemplateException   ex)   {  
      ex.printStackTrace();  
      logger.error("Build   Error"   +   templateFileName,   ex);  
      return   false;  
      }   catch   (IOException   e)   {  
      logger.error("Build   Error"   +   templateFileName,   e);  
      return   false;  
      }  
       
      }  
       
      /**  
        *   創(chuàng)建多級目錄  
        *    
        *   @param   aParentDir  
        *                         String  
        *   @param   aSubDir  
        *                         以   /   開頭  
        *   @return   boolean   是否成功  
        */  
      public   static   boolean   creatDirs(String   aParentDir,   String   aSubDir)   {  
      File   aFile   =   new   File(aParentDir);  
      if   (aFile.exists())   {  
      File   aSubFile   =   new   File(aParentDir   +   aSubDir);  
      if   (!aSubFile.exists())   {  
      return   aSubFile.mkdirs();  
      }   else   {  
      return   true;  
      }  
      }   else   {  
      return   false;  
      }  
      }  
      } 


    別著急,等我學(xué)會了,我一步步說明一什么意思,

    posted on 2008-12-14 10:55 星期五 閱讀(376) 評論(0)  編輯  收藏 所屬分類: J2EE

    主站蜘蛛池模板: 最近免费中文字幕大全高清大全1| 亚洲人成网址在线观看| 4hu四虎免费影院www| 久久亚洲免费视频| 无码一区二区三区AV免费| 国产亚洲人成在线影院| 亚洲AV中文无码乱人伦下载| 亚洲av乱码一区二区三区按摩| 亚洲精品无码激情AV| 麻豆视频免费播放| 久青草国产免费观看| 91午夜精品亚洲一区二区三区| 亚洲成年看片在线观看| 4399影视免费观看高清直播| 亚洲欧洲日产国码二区首页| 亚洲国产成人爱av在线播放| av免费不卡国产观看| 国产精品亚洲午夜一区二区三区| avtt亚洲天堂| 99在线视频免费观看视频| 免费无码作爱视频| 久久亚洲AV成人无码电影| 国产中文字幕免费观看| 亚洲综合免费视频| 99精品视频在线观看免费| 亚洲狠狠婷婷综合久久蜜芽| 亚洲福利在线观看| 久久精品国产精品亚洲人人| 国产一级片免费看| 亚洲男女性高爱潮网站| 一本久久a久久精品亚洲| 中文成人久久久久影院免费观看| 亚洲综合色丁香婷婷六月图片 | 亚洲国产综合无码一区二区二三区| 999久久久免费精品播放| 久草免费福利在线| 黄色网址免费在线| 亚洲国产精品18久久久久久| 亚洲六月丁香六月婷婷色伊人| 亚洲国产精品成人久久| 国产91精品一区二区麻豆亚洲|