all the learning we must first set up the STRUTS2 environment (1, import the corresponding jar package, 2, web.xml,3, Struts.xml)Section I: Introduction to Internationalization
Internationalization (internationlization), in layman's words, is to enable the software to support multiple languages.
Let the Americans see is English, let the Chinese see Chinese
Section II: STRUTS2 Internationalization settings
<constant name= "struts.custom.i18n.resources" value= "Wishwzp" ></constant>
<s:text name= "" ></s:text> Access international resources
Struts.xml
1 <?XML version= "1.0" encoding= "UTF-8"?>2 <!DOCTYPE Struts public3 "-//apache software foundation//dtd Struts Configuration 2.0//en"4 "Http://struts.apache.org/dtds/struts-2.0.dtd">5 6 <Struts>7 8 <constantname= "Struts.custom.i18n.resources"value= "Wishwzp"></constant>9 Ten </Struts>
Wishwzp.properties File Contents: (This is the default)
username=\u7528\u6237\u540d
password=\u5bc6\u7801
Login=\u767b\u5f55
WELCOMEINFO=\U6B22\U8FCE{0}
Wishwzp_zh_cn.properties File Contents: (This is in Chinese)
username=\u7528\u6237\u540d
password=\u5bc6\u7801
Login=\u767b\u5f55
WELCOMEINFO=\U6B22\U8FCE{0}
Wishwzp_en_us.properties File Contents: (This is in English)
Username=username
Password=password
Login=login
WELCOMEINFO=WELCOME{0}
The above \u7528\u6237\u540d ("User name" Chinese to Unicode to "\u7528\u6237\u540d")
\u5bc6\u7801 ("Password" Chinese to Unicode to "\u5bc6\u7801")
\u767b\u5f55 ("Login" Chinese to Unicode to "\\u767b\u5f55")
\U6B22\U8FCE ("Welcome" Chinese to Unicode to "\U6B22\U8FCE")
Are all Unicode-based
Unicode conversion tool Baidu Unicode encoding conversion-webmaster Tools
login.jsp
1 <%@ Page Language="Java"ContentType="text/html; Charset=utf-8"2 pageencoding="UTF-8"%>3 <%@taglib prefix="s"URI="/struts-tags" %>4 <!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd ">5 <HTML>6 <Head>7 <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8">8 <title>Insert Title here</title>9 </Head>Ten <Body> One <Table> A <TR> - <TD><S:textname= "UserName"></S:text></TD> - <TD> the <inputtype= "text"/> - </TD> - </TR> - <TR> + <TD><S:textname= "Password"></S:text></TD> - <TD> + <inputtype= "text"/> A </TD> at </TR> - <TR> - <TD> - <inputtype= "button"value= "<s:text name= ' login ' ></s:text>"/> - </TD> - </TR> in </Table> - </Body> to </HTML>
welcome.jsp
1 <%@ Page Language="Java"ContentType="text/html; Charset=utf-8"2 pageencoding="UTF-8"%>3 <%@taglib prefix="s"URI="/struts-tags" %>4 <!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd ">5 <HTML>6 <Head>7 <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8">8 <title>Insert Title here</title>9 </Head>Ten <Body> One <S:textname= "Welcomeinfo"> A <S:param>Jack</S:param> - </S:text> - </Body> the </HTML>
(vi) STRUTS2 internationalization