資源文件的命" />

欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

Struts2.0國際化支持

系統 2101 0

每種框價都會有國際化的支持,struts2的國際化大致上分為頁面的國際化,Action的國際化以及xml的國際化

首先在struts.properties文件中加入以下內容:
struts.custom.i18n.resources=messageResource
或在struts.xml中加入
<constant name="struts.custom.i18n.resources" value="messageResource"></constant>

資源文件的命名格式: 名稱_語言代碼_國家代碼. Properties
如果創建中文和英語國際化,那么資源文件名稱為
messageResource_zh_CN.properties和messageResource_en_US.properties

1. jsp頁面的國際化
通過使用標簽<s:text name="label.helloWorld"/>輸出國際化
label.helloWorld為資源文件中定義的key


在messageResource_en_US.properties加入以下內容
label.hello=hello {0}
label.helloWorld=hello,world

在messageResource_zh_CN.properties加入以下內容
label.hello=你好 {0}
label.helloWorld=你好,世界

(1). <s:text name="label.helloWorld"/>
<s:property value="%{getText('label.helloWorld')}"/>
上面兩個都為輸出一個hello word的兩種表示

<s:textfield name="name" key="label.helloWorld"/>
<s:textfield name="name" label="%{getText('label.helloWorld')}"/>
顯示一個文本框,文本框的標題進行國際化

(2). 使用<s:i18n>標簽指定從某個特定的資源文件中取數據
<s:i18n name="messageResource">
?? <s:text name="label.helloWorld"></s:text>
</s:i18n>
指定在從messageResource取資源

(3).
<s:text name="label.hello">
?? <s:param>callan</s:param>
</s:text>
使用帶參數的資源.<s:param>可以替換label.hello=hello {0}中的{0}

2. Action的國際化
Action的國際化主要是通過getText(String key)方法實現的

Java代碼 復制代碼
  1. public String execute() throws Exception { ??
  2. ??
  3. ???????? ??
  4. ??
  5. ???????? // getText(String) string為key ??
  6. ??
  7. ???????? String str1 = getText( "label.helloWorld" ); ??
  8. ??
  9. ???????? System.out.println(str1); ??
  10. ??
  11. ???????? ??
  12. ??
  13. ???????? // 帶參數的 ??
  14. ??
  15. ???????? String str2 = getText( "label.hello" , new String[]{ "fjf" }); ??
  16. ??
  17. ???????? System.out.println(str2); ??
  18. ??
  19. ???? ??
  20. ??
  21. ???????? // 與上一種實現一樣 ??
  22. ??
  23. ???????? List l = new ArrayList(); ??
  24. ??
  25. ???????? l.add( "callan" ); ??
  26. ??
  27. ???????? String str3 = getText( "label.hello" ,l); ??
  28. ??
  29. ???????? System.out.println(str3); ??
  30. ??
  31. ???????? ??
  32. ??
  33. ???????? return SUCCESS; ??
  34. ??
  35. ???? }??
Java代碼 復制代碼
  1. public String execute() throws Exception { ??
  2. ??
  3. ???????? ??
  4. ??
  5. ???????? // getText(String) string為key ??
  6. ??
  7. ???????? String str1 = getText( "label.helloWorld" ); ??
  8. ??
  9. ???????? System.out.println(str1); ??
  10. ??
  11. ???????? ??
  12. ??
  13. ???????? // 帶參數的 ??
  14. ??
  15. ???????? String str2 = getText( "label.hello" , new String[]{ "fjf" }); ??
  16. ??
  17. ???????? System.out.println(str2); ??
  18. ??
  19. ???? ??
  20. ??
  21. ???????? // 與上一種實現一樣 ??
  22. ??
  23. ???????? List l = new ArrayList(); ??
  24. ??
  25. ???????? l.add( "callan" ); ??
  26. ??
  27. ???????? String str3 = getText( "label.hello" ,l); ??
  28. ??
  29. ???????? System.out.println(str3); ??
  30. ??
  31. ???????? ??
  32. ??
  33. ???????? return SUCCESS; ??
  34. ??
  35. ???? }??
    public String execute() throws Exception {

  

  // getText(String) string為key

  String str1 = getText("label.helloWorld");

  System.out.println(str1);

  

  // 帶參數的

  String str2 = getText("label.hello",new String[]{"fjf"});

  System.out.println(str2);

 

  // 與上一種實現一樣

  List l = new ArrayList();

  l.add("callan");

  String str3 = getText("label.hello",l);

  System.out.println(str3);

  

  return SUCCESS;

 }
  

3. 參數化國際化
在messageResource_en_US.properties加入以下內容
userName=userName
userName.required=${getText('userName')} is required

在messageResource_zh_CN.properties加入以下內容
userName=用戶名
userName.required=${getText('userName')} 不能為空

在Action中
String str4 = getText("userName.required");
System.out.println(str4);

userName.required=${getText('userName')}會取國際化的用戶名

4. 使用校驗框價時,提示信息可以國際化
?? <field name="userName">
?? <field-validator type="requiredstring">
??? <message key=”userName.required”> </message>
?? </field-validator>
</field>


國際化資源文件分為三種級別
(1) 全局資源文件,可以被整個應該程序引用,也就是struts.custom.i18n.resources=messageResource指定的文件
(2) 包級資源文件,每個包的根目錄下可以新建資源文件,僅被當前包中的類訪問.文件名格式為:package_語言代碼_國家代碼.
(3) Action級資源文件,僅被當前Action引用,名稱為action名_語言代碼_國家代碼
查找順序為從小范圍到大范圍, Action級優先級最大

?

轉載:http://hi.baidu.com/83300409/blog/item/e3bc19a05c091b83471064ba.html

Struts2.0國際化支持


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 91久久亚洲国产成人精品性色 | 国产精品久久久久无码av | 日韩电影免费在线观看中文字幕 | 福利色| 日日摸夜夜爽 | 国产午夜精品理论片影院 | 日本人毛片 | 成人亚洲A片V一区二区三区婷婷 | 日本在线网站 | 欧美大片一区二区三区 | 999宝藏网 | 丁香综合五月 | 中文字幕第一页在线 | 这里只有精品在线视频观看 | 国产精品99久久久久久www | 国产色| 欧美爱爱视频网站 | 嫩草影院在线免费观看 | 国产精品三级a三级三级午夜 | 色综合视频在线观看 | 亚洲综合久久久久久中文字幕 | 91三级 | 国产成人小视频在线观看 | 免费v片在线观看 | 欧美精品欧美极品欧美激情 | 一区二区三区日 | 中文字幕乱码一区二区三区 | 国产精品综合色区在线观看 | 免费午夜电影 | 91九色视频在线播放 | 久久午夜影视 | 上将的炮灰前妻重生了 | 亚洲午夜精品国产电影在线观看 | 国产91久久最新观看地址 | 男女猛烈激情xx00免费视频 | 欧美成年网站 | 波多野结衣亚洲 | 黄a在线观看 | 国产精品免费观看视频 | 精品欧美一区手机在线观看 | 日韩精品视频免费 |