JSP 之國際化

來源:互聯網
上載者:User

標籤:bean   mat   type   etl   val   name   美國   png   http   

 

 

 

 

 

 

 

 

 

 

  • 匯入 <%@ taglib url="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
  • 建立三個語言設定檔,以guo.properties為基準

1 <body>2     <fmt:setLocale value="en_us"/>    //強行將瀏覽器中的語言編碼設定為ja3      <fmt:bundle basename="guo" >4         <fmt:message key="gretting"></fmt:message>5     </fmt:bundle> 
6    <c:set var="price" value="1000"></c:set>
    <fmt:formatNumber type="currency" value="${price }"></fmt:formatNumber>
7 </body>

  結果:

 

 

  //basename="guo" 不能加副檔名,表示guo.properties為基準配置,<fmt:message key="gretting"> 表示輸出key為gretting的值,如果此時瀏覽器的語言優先順序

是中文的話,那麼顯示中文配置guo_zh.properties中的gretting的值,如果此時瀏覽器的語言優先順序是日文的話,那麼顯示日文配置guo_ja.properties中的gretting的值.

 如果瀏覽器中是其他語言優先的話,則預設顯示基準配置(guo.properties)中的key值。

 //<fmt:formatNumber type="currency" value="${price }"></fmt:formatNumber>  用於顯示當前瀏覽器的語言地區的貨幣符號。如,<fmt:setLocale value="en_us"/>將語言編碼強轉為美國英文,所以貨幣為美元符。

 

 

1 <body>2      <fmt:setLocale value="zh_CN"/>3      <fmt:bundle basename="guo" >4         <fmt:message key="gretting"></fmt:message>5     </fmt:bundle> 6 7 <jsp:useBean id="now" class="java.util.Date"></jsp:useBean>8 <fmt:formatDate value="${now}" />9 </body>

結果:

  //<fmt:formatDate value="${now}" /> 將now對象用當前瀏覽器的語言地區的風格顯示。

 

JSP 之國際化

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.