zoukankan      html  css  js  c++  java
  • java学习笔记 (9) —— Struts2 国际化

    1、Test.java

    package com.i18n;
    
    import java.util.Locale;
    
    public class Test1 {
    
        public static void main(String[] args) 
        {
            Locale[] locales = Locale.getAvailableLocales();
            for(Locale locale: locales){
                System.out.println(locale.getDisplayCountry() + " : " + locale.getCountry());
            }
        }
    }

    2、Test2.java

    package com.i18n;
    
    import java.util.*;
    
    public class Test2 {
    
        public static void main(String[] args) 
        {
            //获取本地locale
            Locale locale = Locale.getDefault();
            ResourceBundle bundle = ResourceBundle.getBundle("hellofile",locale);
            String value = bundle.getString("hello");
            System.out.println(value);
        }
    }

     3、Test3.java

    package com.i18n;
    
    import java.text.MessageFormat;
    import java.util.Locale;
    import java.util.ResourceBundle;
    
    
    public class Test3 {
        
        public static void main(String[] args) {
            Locale locale = Locale.getDefault();
            ResourceBundle bundle = ResourceBundle.getBundle("hellofile",locale);
            String value = bundle.getString("hello");
            String result = MessageFormat.format(value,new Object[]{"北京"});
            System.out.println(result);
        }
    }

    4、定义properties文件

    hellofile_en_US.properties

      hello = hello:{0}

    hellofile_zh_CN.properties

      hello = u4f60u597d : {0}

    Struts2 实现国际化

    1、配置struts.xml文件

            <!-- 找配置文件 以  message 开头的信息 -->
            <constant name="struts.custom.i18n.resources" value="message"></constant>

    2、建立properties 文件名为 message

      message_en_US.properties —— addUser = Add User Information

      message_zh_CN.properties —— addUser = u6dfbu52a0u7528u6237

    3、修改register.jsp

          <center>
              <s:text name="addUser"></s:text>
          </center>

    4、根据浏览器的httpheader ,决定输出内容

  • 相关阅读:
    hive基本操作与应用
    用mapreduce 处理气象数据集
    熟悉常用的HBase操作,编写MapReduce作业
    爬虫大作业
    第三章 熟悉常用的HDFS操作
    数据结构化与保存
    获取全部校园新闻
    爬取校园新闻首页的新闻的详情,使用正则表达式,函数抽离
    网络爬虫基础练习
    Hadoop综合大作业
  • 原文地址:https://www.cnblogs.com/cklovefan/p/5266721.html
Copyright © 2011-2022 走看看