标签:RoCE 默认 parameter javautil nali 简写 选择 javaweb 查看
i18n_en_US.properties
username=username
password=password
sex=sex
age=age
regist=regist
boy=boy
email=email
girl=girl
reset=reset
submit=submit
i18n_zh_CN.properties
username=用户名
password=密码
sex=性别
age=年龄
regist=注册
boy=男
girl=女
email=邮箱
reset=重置
submit=提交
java中的Locale
import java.util.Locale;
public void test(){
//获取系统默认的语言,国家信息
Locale aDefault = Locale.getDefault();
System.out.println(aDefault);//zh_CN
//查看全部语言
for (Locale availableLocale : Locale.getAvailableLocales()) {
System.out.println(availableLocale);
}
//获取中文,中文的常量的Locale 对象
System.out.println(Locale.CHINA);//zh_CN
// 获取英文,美国的常量的Locale 对象
System.out.println(Locale.US);//en_US
}
public void test1(){
//获取中文Locale对象
Locale locale = Locale.CHINA;
//根据上面的Locale对象,加载不同的配置文件
ResourceBundle bundle = ResourceBundle.getBundle("i18n", locale);
System.out.println(bundle.getString("username"));
System.out.println(bundle.getString("password"));
}
<body>
<title>i18n国际化</title>
<base href="http://localhost:8080/JavaWeb4/">
<%
String language = request.getParameter("Language");
Locale locale = null;
if ("ZG".equals(language)){
locale = Locale.CHINA;
}else if ("US".equals(language)){
locale = Locale.US;
}else {
locale = request.getLocale();
}
ResourceBundle bundle = ResourceBundle.getBundle("i18n", locale);
%>
<center>
<h1><%=bundle.getString("regist")%>
</h1>
<table>
<form action="">
<tr>
<td><%=bundle.getString("username")%>
</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td><%=bundle.getString("password")%>
</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td><%=bundle.getString("sex")%>
</td>
<td><input type="text" name="sex"></td>
</tr>
<tr>
<td><%=bundle.getString("age")%>
</td>
<td><input type="text" name="age"></td>
</tr>
<tr>
<td><%=bundle.getString("email")%>
</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="<%=bundle.getString("submit")%>">
<input type="reset" value="<%=bundle.getString("regist")%>"></td>
</tr>
<tr>
<td colspan="2" align="center">
<a href="jsonAjax/i18n.jsp?Language=ZG">中文</a>
<a href="jsonAjax/i18n.jsp?Language=US">English</a>
</td>
</tr>
</form>
</table>
</center>
</body>
使用JSTL库
<body>
<title>i18n国际化</title>
<base href="http://localhost:8080/JavaWeb4/">
//根据请求参数Language获取语言
<fmt:setLocale value="${param.Language}"/>
//根据语言选择不同的配置文件
<fmt:setBundle basename="i18n"/>
<center>
<h1><fmt:message key="regist"/></h1>
<table>
<form action="">
<tr>
<td><fmt:message key="username"/>
</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td><fmt:message key="password"/>
</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td><fmt:message key="sex"/>
</td>
<td><input type="text" name="sex"></td>
</tr>
<tr>
<td><fmt:message key="age"/>
</td>
<td><input type="text" name="age"></td>
</tr>
<tr>
<td><fmt:message key="email"/>
</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="<fmt:message key="submit"/>">
<input type="reset" value="<fmt:message key="regist"/>"></td>
</tr>
<tr>
<td colspan="2" align="center">
<a href="jsonAjax/i18n2.jsp?Language=zh_CN">中文</a>
<a href="jsonAjax/i18n2.jsp?Language=en_US">English</a>
</td>
</tr>
</form>
</table>
</center>
</body>
标签:RoCE 默认 parameter javautil nali 简写 选择 javaweb 查看
原文地址:https://www.cnblogs.com/MLYR/p/14406804.html