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

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

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

    道非道 非常道

    勤思、謹言、慎行、厚積、薄發

    統計

    web

    天圓

    經濟 政治 軍事

    鍵康

    [轉]jsp生成靜態頁程序

    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()   {  
      //   設置freemarker的參數  
      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);  
      }  
      }  
       
      /**  
        *   生成靜態文件  
        *    
        *   @param   templateFileName  
        *                         模版名稱eg:(biz/order.ftl)  
        *   @param   propMap  
        *                         用于處理模板的屬性Object映射  
        *   @param   htmlFilePath  
        *                         要生成的靜態文件的路徑,相對設置中的根路徑,例如   "/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");  
      //   創建生成文件目錄  
      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;  
      }  
       
      }  
       
      /**  
        *   創建多級目錄  
        *    
        *   @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;  
      }  
      }  
      } 


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

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

    主站蜘蛛池模板: 亚洲人成在久久综合网站| 亚洲色精品88色婷婷七月丁香| ASS亚洲熟妇毛茸茸PICS| 日韩免费无砖专区2020狼| 小说区亚洲自拍另类| 亚洲国产精品SSS在线观看AV| 在线视频精品免费| 国产亚洲蜜芽精品久久| 亚洲日本在线看片| 免费一级做a爰片久久毛片潮喷| 性xxxx视频免费播放直播| 午夜在线a亚洲v天堂网2019| 亚洲日韩国产精品第一页一区| 久久亚洲国产成人影院网站| 国产乱码免费卡1卡二卡3卡| 亚美影视免费在线观看| wwwxxx亚洲| 亚洲欧美中文日韩视频| 亚洲成人动漫在线| 相泽亚洲一区中文字幕| 亚洲精品中文字幕乱码三区| 亚洲&#228;v永久无码精品天堂久久| 日本在线看片免费人成视频1000| 综合一区自拍亚洲综合图区| 一级特黄色毛片免费看| 国产精品亚洲综合五月天| 亚洲AV无码专区在线电影成人| 亚洲国产电影在线观看| 国产亚洲中文日本不卡二区| 成a人片亚洲日本久久| 好吊色永久免费视频大全| 亚洲6080yy久久无码产自国产| 免费的黄网站男人的天堂| 亚洲精品国产综合久久久久紧| 亚洲人成影院77777| 国产精品亚洲一区二区三区在线观看| 人妻仑乱A级毛片免费看| 精品特级一级毛片免费观看| 久久免费99精品国产自在现线| 无码人妻丰满熟妇区免费| 欧洲精品成人免费视频在线观看|