lyyb2001

          只是為方便自己找記錄而已
          posts - 57, comments - 27, trackbacks - 0, articles - 5
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 ::  :: 管理

          struts處理國際化問題

          Posted on 2007-04-30 17:43 skycity 閱讀(409) 評論(0)  編輯  收藏 所屬分類: MVC框架

          處理國際化問題得在先配置好struts的環(huán)境下才能進行的,關(guān)于如何配置struts環(huán)境,網(wǎng)上搜一下,已經(jīng)一大巴了,沒必要我再在這里羅嗦了。
          主要說明一下如何解決struts下惡國際化問題,剛摸索這個問題的時候走了很多錯路,害我整了一兩個小時,寫下來主要是為了以后自己或者初學(xué)的人不要再走錯路。
          真正要實現(xiàn)struts國際化很簡單。
          struts國際化訪問的都是目錄下的properties資源文件。我們先建幾個資源文件
          ApplicationResource_zh.bak(中文源文件)
          index.jsp.welcome=你好
          index.jsp.userid=用戶編號
          index.jsp.pass=用戶密碼
          建Application_en.properties
          index.jsp.welcome=welcome
          index.jsp.userid=User ID
          index.jsp.pass=Password
          現(xiàn)在將ApplicationResource_zh.bak轉(zhuǎn)換為unicode編碼的文件
          native2ascii -encoding -GBK ApplicationResource_zh.bak ApplicationResource_zh_CN.properties
          native2ascii -encoding -Big5 ApplicationResource_zh.bak ApplicationResource_zh_TW.properties
          注意:資源文件的命名規(guī)則:ApplicationResource_國家_語言。還有千萬注意大小寫。我自以為是的吧zh弄成大寫,害我整了好久都沒效果,真是丟臉
          接著可以在struts-config.xml中配置資源文件
          ?<message-resources parameter="net.skycity.ApplicationResource" />
          jsp中頭部設(shè)置為:
          <%@ page contentType="text/html; charset=UTF-8"%>
          默認國際化
          <%@ taglib uri="/struts-bean" prefix="bean"%>
          <%@ taglib uri="/struts-html" prefix="html"%>
          <%@ taglib uri="/struts-logic" prefix="logic"%>
          <%@ page import="org.apache.struts.Globals"%>
          <html:html locale="true">
          ?<bean:message key="index.jsp.welcome"/>
          </html:html>
          變更不同的國家,可以在瀏覽器的工具—>Internet選項->語言設(shè)置
          刷新頁面,就會顯示不同國家的資源文件名



          Lyyb2001

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 景德镇市| 兰溪市| 大竹县| 漳州市| 万年县| 增城市| 乐业县| 樟树市| 保定市| 措美县| 罗山县| 福清市| 大姚县| 肇东市| 武鸣县| 闵行区| 碌曲县| 建德市| 衡山县| 府谷县| 柳河县| 华安县| 正阳县| 新田县| 小金县| 汶川县| 成都市| 黄冈市| 兴国县| 博兴县| 襄汾县| 垣曲县| 若羌县| 石门县| 丰城市| 八宿县| 阿尔山市| 鹿泉市| 邵阳市| 大名县| 公安县|