Java Learning Notes (9)--struts2 internationalization [1]

Source: Internet
Author: User

1, Test.java

 Package com.i18n; Import Java.util.Locale;  Public class Test1 {    publicstaticvoid  main (string[] args)     {        = locale.getavailablelocales ();          for (Locale locale:locales) {            locale.getcountry ());     }}}

2, Test2.java

 Package com.i18n; import java.util.*;  Public class Test2 {    publicstaticvoid  main (string[] args)     {         // get local locale        Locale locale = locale.getdefault ();         = Resourcebundle.getbundle ("Hellofile", locale);         = bundle.getstring ("Hello");        System.out.println (value);}    }

3, Test3.java

 Packagecom.i18n;ImportJava.text.MessageFormat;ImportJava.util.Locale;ImportJava.util.ResourceBundle; Public classTest3 { Public Static voidMain (string[] args) {locale locale=Locale.getdefault (); ResourceBundle Bundle= Resourcebundle.getbundle ("Hellofile", Locale); String value= bundle.getstring ("Hello"); String result= Messageformat.format (Value,Newobject[]{"Beijing"});    SYSTEM.OUT.PRINTLN (result); }}

4. Define Properties File

Hellofile_en_us.properties

Hello = hello:{0}

Hellofile_zh_cn.properties

Hello = \u4f60\u597d: {0}

Struts2 for internationalization

1. Configuring the Struts.xml File

        <!-- Find the configuration file  to  -        <  name= "Struts.custom.i18n.resources"  value= "message"> </constant>

2. Build properties file name as Message

Message_en_us.properties--adduser = Add User Information

Message_zh_cn.properties--adduser = \u6dfb\u52a0\u7528\u6237

3, modify the register.jsp

      < Center >          <  name= "AddUser"></s:text>      </  Center>

4, according to the browser Httpheader, determine the output content

Java Learning Notes (9)--struts2 internationalization [1]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.