In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to achieve struts2 internationalization". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's ideas to study and learn "how to achieve struts2 internationalization".
Internationalization is used in 1.java.
Internationalization is called internationalization for short i18n.
Internationalization is achieved in java by configuring a properties file named baseName-language-country.properties and content in the form of key-value.
You can use the Local class to see which countries and languages java supports internationalization.
Local [] ls=Local.getAvailableLocales (); for (Local local:ls) {System.out.println (local.getDisplayCountry () + "+ local.getCountry ()); System.out.println (local.getDisplayLanguage () +" + local.getLanguage ()); System.out.println ("-");}
Get the content according to the resource file.
/ / obtain the local attribute Local l=Local.getDefault (); / / obtain the resource file ResourceBundle rb=ResourceBundle.getBundle ("message", l) whose baseName is message under the classes path according to the local language; / / get the value of key String text=rb.getString ("username"); / / you can pass in parameters if the resource file is defined in this way: username= {0} user name String textp=MessageFormat.format (rb.getString ("username"), "normal"); 2.struts2 internationalization usage
First configure baseName to specify the resource file, which can be configured in the struts.xml file.
Then add resource files under the classes drive.
How to write the content of the resource file.
a. No parameters: key=value
b. Indexed parameter: key= {0} value {1}
c. With expression parameter: key=$ {username} value means that the username value is obtained directly from the ValueStack. In this way, there is no need to pass the parameter manually like (b).
Access internationalization messages.
Jsp page: or value1
In action: getText () method
Management of 3.struts2 resource files
There are four types of resource files:
a. Global scope, under the classes path.
BaseName-language-country.properties. Such as message_zh_CN.properties
b. Package range, under the package root path.
Package-language-country.properties. Such as package_zh_CN.properties
c. Class scope, under the same path of the class.
ActionName-language-country.properties. Such as LoginAction_zh_CN.properties
d. Temporary resource file, use tags on the jsp page to specify the resource file under the classes path.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.