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

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

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

    隨筆 - 119  文章 - 3173  trackbacks - 0
    <2007年5月>
    293012345
    6789101112
    13141516171819
    20212223242526
    272829303112
    3456789

    交友莫獨(dú)酒,茅臺(tái)西鳳游。
    口干古井貢,心徜洋河流。
    稱多情杜康,趟無量雙溝。
    贊中華巍巍,無此不銷愁。

    常用鏈接

    留言簿(68)

    隨筆分類(136)

    隨筆檔案(122)

    最新隨筆

    搜索

    •  

    積分與排名

    • 積分 - 525163
    • 排名 - 93

    最新評(píng)論

    FreeMarkerTest:
    ?1?import?java.io.BufferedWriter;
    ?2?import?java.io.File;
    ?3?import?java.io.FileOutputStream;
    ?4?import?java.io.OutputStreamWriter;
    ?5?import?java.io.Writer;
    ?6?import?java.util.HashMap;
    ?7?import?java.util.Locale;
    ?8?
    ?9?import?freemarker.template.Configuration;
    10?import?freemarker.template.Template;
    11?
    12?public?class?FreeMarkerTest?{
    13?
    14?????public?static?void?main(String[]?args)?{
    15?????????FreeMarkerTest?test?=?new?FreeMarkerTest();
    16?????????test.getFile();
    17?????????test.getFile(Locale.JAPAN);
    18?????}
    19?????
    20?????public?void?getFile()?{
    21?????????Configuration?freemarkerCfg?=?new?Configuration();
    22?????????freemarkerCfg.setClassForTemplateLoading(this.getClass(),"/");
    23?????????freemarkerCfg.setEncoding(Locale.getDefault(),"UTF-8");
    24?????????Template?template;
    25?????????try?{
    26?????????????template?=?freemarkerCfg.getTemplate("t.ftl");
    27?????????????template.setEncoding("UTF-8");
    28?????????????File?htmlFile?=?new?File("t.html");
    29?????????????Writer?out?=?new?BufferedWriter(new?OutputStreamWriter(
    30?????????????????????new?FileOutputStream(htmlFile),?"UTF-8"));
    31?????????????HashMap?propMap?=?new?HashMap();
    32?????????????propMap.put("user",?"hermit");
    33?????????????template.process(propMap,?out);
    34?????????????out.flush();
    35?????????}?catch?(Exception?e)?{
    36?????????????e.printStackTrace();
    37?????????}
    38?????}
    39?????
    40?????public?void?getFile(Locale?loc)?{
    41?????????Configuration?freemarkerCfg?=?new?Configuration();
    42?????????freemarkerCfg.setClassForTemplateLoading(this.getClass(),"/");
    43?????????freemarkerCfg.setEncoding(Locale.getDefault(),"UTF-8");
    44?????????Template?template;
    45?????????try?{
    46?????????????template?=?freemarkerCfg.getTemplate("t.ftl",loc);
    47?????????????template.setEncoding("UTF-8");
    48?????????????File?htmlFile?=?new?File("t_"+loc.getLanguage()+"_"+loc.getCountry()+".html");
    49?????????????Writer?out?=?new?BufferedWriter(new?OutputStreamWriter(
    50?????????????????????new?FileOutputStream(htmlFile),?"UTF-8"));
    51?????????????HashMap?propMap?=?new?HashMap();
    52?????????????propMap.put("user",?"hermit");
    53?????????????template.process(propMap,?out);
    54?????????????out.flush();
    55?????????}?catch?(Exception?e)?{
    56?????????????e.printStackTrace();
    57?????????}
    58?????}
    59?
    60?}
    61?


    t.ftl
    <html>
    <head>
    ??
    <title>Welcome!</title>
    ??
    <META?HTTP-EQUIV="Content-Type"?CONTENT="text/html;?charset=utf-8">
    </head>
    <body>
    ??
    <h1>Welcome?${user}!</h1>
    </body>
    </html>??


    t_zh_CN.ftl
    <html>
    <head>
    ??
    <title>歡迎!</title>
    ??
    <META?HTTP-EQUIV="Content-Type"?CONTENT="text/html;?charset=utf-8">
    </head>
    <body>
    ??
    <h1>你好?${user}!</h1>
    </body>
    </html>??


    freemarker支持多語言國際化,只要把模板名稱安裝資源文件的寫法就可以了,也就是name_語言_國家地區(qū).ftl

    如果找不到對(duì)應(yīng)的語言,就會(huì)用默認(rèn)語言的模板。

    順便抱怨一下,freemarker對(duì)于空值的處理太霸道了,沒有值你就寫個(gè)空或者寫KEY也可以啊,弄一堆出錯(cuò)信息在那。。。。。。。。。。。。。。
    posted on 2007-05-08 15:23 交口稱贊 閱讀(3716) 評(píng)論(5)  編輯  收藏 所屬分類: freemarker

    FeedBack:
    # re: 用freemarker生產(chǎn)靜態(tài)頁面文件,支持多語言 2007-05-08 15:35 killer->
    順便抱怨一下,freemarker對(duì)于空值的處理太霸道了,沒有值你就寫個(gè)空或者寫KEY也可以啊,弄一堆出錯(cuò)信息在那。。。。。。。。。。。。。。

    這正是我喜歡freemarker的地方不像velocity那樣, 什么反應(yīng)也沒有,錯(cuò)了都不知道.  回復(fù)  更多評(píng)論
      
    # re: 用freemarker生產(chǎn)靜態(tài)頁面文件,支持多語言 2007-05-08 15:37 交口稱贊
    呵呵,我倒是希望他把KEY值留在那,就像做RCP開發(fā)時(shí)候那樣。
    這樣比較好。。。。。。

    留空確實(shí)不好。。。。  回復(fù)  更多評(píng)論
      
    # re: 用freemarker生產(chǎn)靜態(tài)頁面文件,支持多語言 2007-05-09 00:05 yadan
    加上個(gè)! 后面還可以帶任何默認(rèn)值 很喜歡這種方式。   回復(fù)  更多評(píng)論
      
    # re: 用freemarker生產(chǎn)靜態(tài)頁面文件,支持多語言 2009-03-09 18:34 097
    你好,請(qǐng)問用FREEMARKER在WEB程序中生產(chǎn)靜態(tài)頁面模板文件怎么獲取?  回復(fù)  更多評(píng)論
      
    # re: 用freemarker生產(chǎn)靜態(tài)頁面文件,支持多語言 2011-11-22 09:16 q
    謝謝樓主,正好解決了我的問題。  回復(fù)  更多評(píng)論
      
    主站蜘蛛池模板: 亚洲精品无码专区在线在线播放| 国产成人精品免费视频大全五级| 久久久久久久久无码精品亚洲日韩| 亚洲av无码一区二区三区不卡| 国产网站在线免费观看| 日韩免费人妻AV无码专区蜜桃| 国产一精品一AV一免费| 国产精品免费大片一区二区| 看Aⅴ免费毛片手机播放| 亚洲人片在线观看天堂无码| 中文字幕精品三区无码亚洲| 亚洲GV天堂GV无码男同| 亚洲精品天堂在线观看| 亚洲综合激情五月色一区| 亚洲日本香蕉视频| 亚洲人成综合网站7777香蕉| 亚洲中文字幕久久精品无码A| 精品一区二区三区无码免费直播| 精品免费AV一区二区三区| 美女视频黄视大全视频免费的| 无人视频免费观看免费视频| 可以免费观看的毛片| 最新猫咪www免费人成| 亚洲精品乱码久久久久久| 国产成+人+综合+亚洲专| 无码的免费不卡毛片视频| 午夜dj免费在线观看| 久久久久亚洲精品无码蜜桃| 老司机精品免费视频| 免费欧洲美女牲交视频| 亚洲av无码专区在线电影| 波多野结衣在线免费观看| 亚洲成a人不卡在线观看| 精品四虎免费观看国产高清午夜 | 亚洲www在线观看| 黄视频在线观看免费| 91成人免费福利网站在线| 69av免费视频| 成人在线免费观看| 国产亚洲精AA在线观看SEE| 亚洲一区在线免费观看|