day11-mytag&jst&i18nの代码学习3
来源:互联网 发布:java排班做二休一源码 编辑:程序博客网 时间:2024/06/06 16:26
day11-mytag&jst&i18nの代码学习3
i18n
I18NTest.java(根据设置的语言环境,选择不同的配置文件来取得值)
package com.itheima.i18n.test;import java.util.Locale;import java.util.ResourceBundle;import org.junit.Test;public class I18NTest { @Test public void testI18N(){ ResourceBundle rb = ResourceBundle.getBundle("message",Locale.CHINA);//不帶擴展名就是基名 System.out.println(rb.getString("hello")); }}
message_en_US.properties(英文状态下)
hello=hello world
message_ja_JP.properties(日语环境下)
hello=犬の日(\u72AC\u306E\u65E5)
message_zh_CN.properties(中文环境下)
hello=你好,你吃了吗?
message_zh_HK.properties(香港环境下)
hello=妳吃飯了嗎?(\u59B3\u5403\u98EF\u4E86\u55CE\uFF1F)
message.properties
hello=你好,吃了吗?
01i18n.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <title></title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> </head> <body> 基名:Message?如何确定基名 <% //获取客户端的语言环境 Locale l = request.getLocale(); ResourceBundle rb = ResourceBundle.getBundle("message",l);//用什么资源文件取决于客户端的语言环境 out.write(rb.getString("hello")); %> </body></html>
02i18n.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <title></title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> </head> <body> <!-- EL表达式取request pageContext.getRequest().getLocale()--> <fmt:setLocale value="${pageContext.request.locale }"/><!-- 获取客户端 的语言环境 --> <fmt:setBundle basename="message" var="mybundle"/><!-- 绑定资源文件 --> <fmt:message bundle="${ mybundle}" key="hello"></fmt:message> <% pageContext.setAttribute("now", new Date()); %> <br> 时间: <fmt:formatDate value="${now }" dateStyle="full" timeStyle="full" type="both"/> <br>数字国际化: <% pageContext.setAttribute("mydata", 10000); %> <fmt:formatNumber value="${mydata }" groupingUsed="true" type="currency"></fmt:formatNumber> </body></html>
0 0
- day11-mytag&jst&i18nの代码学习3
- day11-mytag&jst&i18nの代码学习1
- day11-mytag&jst&i18nの代码学习1
- day11-mytag&jst&i18nの代码学习2
- day11-mytag&jst&i18nのPPT学习3
- day11-mytag&jst&i18nのPPTの学习2
- day11-mytag&jst&i18nのPPT学习1
- JST标签学习笔记
- java基础学习day11
- C++ 学习笔记day11
- java学习day11
- java学习day11
- Android学习笔记day11
- java学习day11
- Linux学习-day11
- python学习日志--day11
- 国家语言代码i18n
- 机器学习学习笔记.day11
- ffmpeg解码流程
- 翻转字符串中的单词
- day11-mytag&jst&i18nの代码学习1
- day11-mytag&jst&i18nの代码学习1
- day11-mytag&jst&i18nの代码学习2
- day11-mytag&jst&i18nの代码学习3
- 检测有向图中的环
- 2D游戏
- YUV格式分析
- Java基础视频教程第12天_多线程二之线程间通信
- Merge k Sorted Lists
- CSS3学习笔记
- Secant Method (Website)
- Inverse Quadratic Interpolation (website)