開發門戶**時,我們需要把頁面生成靜態的,以應對大規模的訪問,這篇文章主要介紹了,如何使用freemarker的api將模板檔案(ftl)生成為html檔案
建立gettemplate
方法用於獲取
freemarker的模板
template 物件
public
static
template gettemplate(configuration cfg,string name)
throws
ioexception
建立dowirte
方法用於往磁碟上寫生成好的檔案
public
void
dowirte(template t,string path,mapreq)
catch
(exception e)
} 最後建立
createstaticpage方法
/***
* createftl:此方法用於生成靜態頁
* *
@param
@param
req 模板中需要的引數
* @param
@param
templatepath 模板檔案路徑
* @param
@param
templatefilename 模板檔名
* @param
@param
staticpagename 靜態頁檔名
* @return
void dom物件
* @throws
* @since
codingexample
ver1.1
*/ private
void
createstaticpage(mapreq,string templatepath,string templatefilename,string staticpagename)
catch
(exception e)
} 生成靜態頁時,就按照下面生成就可以
public
void
createjingyanganxiepage()
使用freemarker模板生成word文件
專案中最近用到這個東西,做下記錄。如下圖,先準備好乙個 office2003 word文件當做模板。文件中 姓名 性別和生日已經使用佔位符代替,生成過程中將會根據實際情況進行替換。然後將word文件另存為 word xml文件 完成後,將test.xml重新命名為test.ftl。接下來,實現 如下...
freemarker生成靜態頁面
org.junit.test public void test01 writer out new outputstreamwriter new fileoutputstream webroot html test.html utf 8 輸出流 t.process root,out 動態載入root中...
freemarker生成靜態頁面中文亂碼解決方案
最近做乙個門戶 頁面要求靜態化,就用freemarker的模板,輸出靜態頁面。freemarker的配置什麼的全部設定成utf 8,本以為輸出html正常了,結果檢視靜態頁面裡面中文全亂碼,除錯n久,最後換成gbk,亂碼沒有,好了。但是整體專案是utf 8編碼的,所以gbk基本排除。最後把生成的ht...