lyyb2001

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

          struts處理國際化問題

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

          處理國際化問題得在先配置好struts的環境下才能進行的,關于如何配置struts環境,網上搜一下,已經一大巴了,沒必要我再在這里羅嗦了。
          主要說明一下如何解決struts下惡國際化問題,剛摸索這個問題的時候走了很多錯路,害我整了一兩個小時,寫下來主要是為了以后自己或者初學的人不要再走錯路。
          真正要實現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
          現在將ApplicationResource_zh.bak轉換為unicode編碼的文件
          native2ascii -encoding -GBK ApplicationResource_zh.bak ApplicationResource_zh_CN.properties
          native2ascii -encoding -Big5 ApplicationResource_zh.bak ApplicationResource_zh_TW.properties
          注意:資源文件的命名規則:ApplicationResource_國家_語言。還有千萬注意大小寫。我自以為是的吧zh弄成大寫,害我整了好久都沒效果,真是丟臉
          接著可以在struts-config.xml中配置資源文件
          ?<message-resources parameter="net.skycity.ApplicationResource" />
          jsp中頭部設置為:
          <%@ 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選項->語言設置
          刷新頁面,就會顯示不同國家的資源文件名



          Lyyb2001

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


          網站導航:
           
          主站蜘蛛池模板: 高唐县| 嘉黎县| 芒康县| 丰原市| 建水县| 安新县| 安丘市| 西平县| 防城港市| 鄯善县| 新晃| 香格里拉县| 乡宁县| 子长县| 神木县| 长顺县| 于都县| 勃利县| 五峰| 宝丰县| 梅河口市| 德令哈市| 中牟县| 科技| 边坝县| 武夷山市| 阿克陶县| 安溪县| 阳江市| 元江| 安新县| 微山县| 宝丰县| 泽库县| 中西区| 博野县| 视频| 红河县| 灌阳县| 洛川县| 邛崃市|