主頁 > 知識(shí)庫 > ResourceBundle類在jsp中的國際化實(shí)現(xiàn)方法

ResourceBundle類在jsp中的國際化實(shí)現(xiàn)方法

熱門標(biāo)簽:電子圍欄 阿里云 銀行業(yè)務(wù) 服務(wù)器配置 Linux服務(wù)器 科大訊飛語音識(shí)別系統(tǒng) 團(tuán)購網(wǎng)站 Mysql連接數(shù)設(shè)置

今天第一次聽說頁面國際化這個(gè)詞,所以查資料,順便做了一個(gè)小頁面,做做記錄。

首先是兩個(gè)資源文件,分別為msg_en_US.properties和msg_zh_CN.properties

 

顯然中文字符是需要轉(zhuǎn)換過來的。

這是jsp頁面的代碼

%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

%@page import="java.util.*"%>
!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
html>
 head>
  meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  title>國際化/title>
  style type="text/css">
  div{
   width: 300px;
   text-align: center;
   margin: 0 auto;
  }
  /style>
 /head>
 
 body>
  a href="/International/test.jsp?language=zh" rel="external nofollow" >簡體中文/a>|a href="/International/test.jsp?language=en" rel="external nofollow" >English/a>
  %
   ResourceBundle bund=ResourceBundle.getBundle("msg",request.getLocale());
   String str=request.getParameter("language");
   if(str!=null){
    if("zh".equals(str)){
     bund=ResourceBundle.getBundle("msg",Locale.CHINA);
    }
    else if("en".equals(str)){
     bund=ResourceBundle.getBundle("msg",Locale.US);
    } 
   }
  %>
  div>
   h1>%=bund.getString("inf") %>/h1>
   table>
    tr>
     td>%=bund.getString("name") %>:/td>
     td>input type="text" name="name"/>/td>
    /tr>
    tr>
     td>%=bund.getString("sex") %>:/td>
     td>input type="text" name="sex"/>/td>
    /tr>
    tr>
     td>%=bund.getString("age") %>:/td>
     td>input type="text" name="age"/>/td>
    /tr>
    tr>
     td>%=bund.getString("tel") %>:/td>
     td>input type="text" name="tel"/>/td>
    /tr>
   /table>br/>
   input type="submit" value="%=bund.getString("submit")%>" name="submit"/>
  /div>
 /body>
/html>
 

結(jié)果圖

 

以上這篇ResourceBundle類在jsp中的國際化實(shí)現(xiàn)方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • 聊聊ResourceBundle和properties讀取配置文件的區(qū)別
  • javaweb 國際化:DateFormat,NumberFormat,MessageFormat,ResourceBundle的使用
  • Java ResourceBundle案例詳解

標(biāo)簽:廣元 衡水 棗莊 江蘇 蚌埠 萍鄉(xiāng) 衢州 大理

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ResourceBundle類在jsp中的國際化實(shí)現(xiàn)方法》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266