freemarker生成靜態頁面

2021-08-31 08:13:38 字數 1589 閱讀 1192

@org.junit.test

public void test01()

writer out = new outputstreamwriter(new fileoutputstream(

"webroot\\html\\test.html"), "utf-8"); //輸出流

t.process(root, out); //動態載入root中的資料到test.html。資料在模板中定義好了。

system.out.println("create successfully!");

} catch (unsupportedencodingexception e) catch (filenotfoundexception e) catch (ioexception e) catch (templateexception e)

}

/**

* 生成靜態頁面主方法

* * @param context

* servletcontext

* @param data

* 乙個map的資料結果集

* @param templatepath

* ftl模版路徑

* @param targethtmlpath

* 生成靜態頁面的路徑

*/public static void cratehtml(servletcontext context,

mapdata, string templatepath, string targethtmlpath) catch (exception e)

}

@org.junit.test

public void test01()

//建立html下面年資料夾

dir = new file(newfilepath+"\\"+fileyear);

if(!dir.exists())

//建立年下面月日資料夾

dir = new file(newfilepath+"\\"+fileyear+"\\"+filemmdd);

if(!dir.exists())

writer out = new outputstreamwriter(new fileoutputstream(

newfilepath+"\\"+fileyear+"\\"+filemmdd+"\\test02.html"), "utf-8"); //輸出流

t.process(root, out); //動態載入root中的資料到test.html。資料在模板中定義好了。

system.out.println("create successfully!");

} catch (unsupportedencodingexception e) catch (filenotfoundexception e) catch (ioexception e) catch (templateexception e)

}

JSP靜態頁例項 Freemarker例項

詳細 取得模板檔案 設定生成檔案路徑 載入objectmap中的內容生成檔案 詳細 取得模板檔案 設定生成檔案路徑 載入objectmap中的內容生成檔案 param templatefolder 模板相對於classpath的路徑 param templatefilename 模版名稱 param...

使用freemarker生成靜態頁面

開發門戶 時,我們需要把頁面生成靜態的,以應對大規模的訪問,這篇文章主要介紹了,如何使用freemarker的api將模板檔案 ftl 生成為html檔案 建立gettemplate 方法用於獲取 freemarker的模板 template 物件 public static template ge...

生成靜態頁

先定義乙個staticfilecachemodule 實現ihttpmodule介面 定製beginrequest事件 再定義乙個類 要生成靜態頁面的繼承它就行了 將頁面內容輸出到瀏覽器 response.write pagecontent 當然不要忘在配置web.confing 用模板生成靜態頁 ...