Each box price will have international support, struts2 internationalization is broadly divided into the internationalization of the page, action internationalization and the internationalization of XML
First, add the following in the Struts.properties file:
Struts.custom.i18n.resources=messageresource
Or join in the Struts.xml
<constant name= "struts.custom.i18n.resources" value= "Messageresource" ></constant>
Resource file Naming format: Name _ Language Code _ Country code. Properties
If you create internationalization of Chinese and English, the resource file name is called
Messageresource_zh_cn.properties and Messageresource_en_us.properties
1. The internationalization of JSP pages
/> output internationalization by using the label <s:text name= "Label.helloworld"
Label.helloworld the key defined in the resource file
Add the following in Messageresource_en_us.properties
Label.hello=hello {0}
Label.helloworld=hello,world
Add the following in Messageresource_zh_cn.properties
label.hello= Hello {0}
label.helloworld= Hello, world
(1). <s:text name= "Label.helloworld"/>
<s:property value= "%{gettext (' Label.helloworld ')}"/>
The above two are both representations of the output of a Hello Word
<s:textfield name= "name" key= "Label.helloworld"/>
<s:textfield name= "name" label= "%{gettext (' Label.helloworld ')}"/>
Displays a text box with the title of the text box internationalized
(2). Specify the data from a particular resource file using the <s:i18n> tag
<s:i18n name= "Messageresource" >
<s:text name= "Label.helloworld" ></s:text>
</s:i18n>
Specifies that resources are fetched from the Messageresource
(3).
<s:text name= "Label.hello" >
<s:param>callan</s:param>
</s:text>
Use resource .<s:param> with parameters to replace {0} in Label.hello=hello {0}
2. Internationalization of Action
The internationalization of action is primarily achieved through the GetText (String key) method
Java Code
1. public String execute () throws Exception {
2.
3.
4.
5.//GetText (String) string to key
6.
7. String str1 = GetText ("Label.helloworld");
8.
9. SYSTEM.OUT.PRINTLN (STR1);
10.
11.
12.
13.///with parameter
14.
String str2 = GetText ("Label.hello",new string[]{"FJF"});
16.
System.out.println (STR2);
18.
19.
20.
21.//As with the previous implementation
22.
List L = new ArrayList ();
24.
L.add ("Callan");
26.
A. String STR3 = GetText ("Label.hello", L);
28.
System.out.println (STR3);
30.
31.
32.