<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [TOC] # 創建資源包和資源文件 一個資源包中的每個資源文件都必須擁有共同的基名。 除了基名,每個資源文件的名稱中還必須有標識其本地信息的附加部分。 例如:一個資源包的基名是“MessageResource”,則與中文、英文環境相對應的資源文件名則為: “MessageResource_zh.properties” , “MessageResource_en.properties” ![](https://box.kancloud.cn/b7ef9fa16871e0ec9d8ce80a4b26d1d3_886x288.png) 每個資源包都應有一個默認資源文件,這個文件不帶有標識本地信息的附加部分。 若ResourceBundle對象在資源包中找不到與用戶匹配的資源文件,它將選擇該資源包中與用戶最相近的資源文件,如果再找不到,則使用默認資源文件。例如:MessageResource.properties # 資源文件的書寫格式 資源文件的內容通常采用”關鍵字=值”的形式,軟件根據關鍵字檢索值顯示在頁面上。一個資源包中的所有資源文件的關鍵字必須相同,值則為相應國家的文字。并且資源文件中采用的是properties格式文件,所以文件中的所有字符都必須是ASCII字碼,屬性(properties)文件是不能保存中文的,對于像中文這樣的非ACSII字符,須先進行編碼。 例如: 國際化的中文環境的properties文件 MessageResource_en.properties ~~~ username=username password=password submit=submit ~~~ MessageResource_zh.properties ~~~ username=\u7528\u6237\u540d password=\u5bc6\u7801 submit=\u63d0\u4ea4 ~~~ java提供了一個native2ascII工具用于將中文字符進行編碼處理,native2ascII的用法如下所示 ![](https://box.kancloud.cn/f1dd8ca3ee8c873409379e9041aaa8a3_780x436.png) # 固定文本的國際化 在JavaAPI中提供了一個ResourceBundle類用于描述一個資源包,并且 ResourceBundle類提供了相應的方法getBundle,這個方法可以根據來訪者的國家地區自動獲取與之對應的資源文件予以顯示。 ResourceBundle類提供了一個靜態方法getBundle,該方法用于裝載資源文件,并創建ResourceBundle實例: ~~~ Locale currentLocale = Locale.getDefault(); ResourceBundle myResources =ResourceBundle.getBundle(basename, currentLocale); ~~~ * basename為資源包基名(且必須為完整路徑)。 * 如果與該locale對象匹配的資源包子類找不到。一般情況下,則選用默認資源文件予以顯示 加載資源文件后, 程序就可以調用ResourceBundle實例對象的getString方法獲取指定的資源信息名稱所對應的值。 ~~~ String value = myResources.getString("key"); ~~~ 范例:根據國家地區自動獲取與之對應的資源文件 ~~~ public static void main(String[] args) { //根據資源包基名和語言環境加載對應的語言資源文件 ResourceBundle bundle = ResourceBundle.getBundle("com.jdxia.resource.MessageResource", Locale.CANADA); String username = bundle.getString("username"); String password = bundle.getString("password"); System.out.println(username); System.out.println(password); } ~~~ # web中使用 ~~~ //獲取瀏覽器端的國家語言信息 Locale locale = request.getLocale(); ~~~ ~~~ //獲取瀏覽器端的國家語言信息 Locale locale = request.getLocale(); //根據資源包基名和語言環境加載對應的語言資源文件 ResourceBundle bundle = ResourceBundle.getBundle("com.jdxia.resource.MessageResource", Locale.CANADA); String username = bundle.getString("username"); String password = bundle.getString("password"); System.out.println(username); System.out.println(password); ~~~ # jsp中使用 使用jstl標簽,導入標簽 ~~~ <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> ~~~ ~~~ <!-- fmt標簽默認使用瀏覽器的locale --> <!-- 設置基礎文件名 --> <fmt:setBundle basename="com.jdxia.resource.MessageResource" /> <fmt:message key="username"></fmt:message> <br> <fmt:message key="password"></fmt:message> <br> ~~~ # 占位符 properties ~~~ info= \u6b22\u8fce ${0} \u56de\u6765 ~~~ jsp ~~~ <fmt:setBundle basename="com.jdxia.resource.MessageResource" /> <fmt:message key="info"> <fmt:param>${param.username}</fmt:param> </fmt:message> ~~~ # 日期國際化 ~~~ <fmt:setBundle basename="com.jdxia.resource.MessageResource" /> <!-- type屬性可以不寫,type寫上是加時分秒的 dateStyle可以不寫, 寫上full是加星期的 2018年8月14日 星期二 寫上short是不加日期的精簡 18-8-14 timeStyle可以不寫, 寫long是這種形式 上午12時16分29秒 寫full是這種形式,加上時區 上午12時17分22秒 CST --> <fmt:formatDate value="<%=new Date() %>" type="both" dateStyle="short" timeStyle="full"></fmt:formatDate> ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看