(六)Struts2 国际化

所有的学习我们必须先搭建好Struts2的环境(1、导入对应的jar包,2、web.xml,3、struts.xml)

第一节:国际化简介

国际化(Internationlization),通俗地讲,就是让软件实现对多种语言的支持。

让美国人看到的是英语,让中国人看到的汉语

第二节:Struts2 国际化设置

<constant name="struts.custom.i18n.resources" value="wishwzp"></constant>

 

<s:text name=""></s:text> 访问国际化资源

struts.xml

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE struts PUBLIC
 3     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
 4     "http://struts.apache.org/dtds/struts-2.0.dtd">
 5 
 6 <struts>
 7     
 8   <constant name="struts.custom.i18n.resources" value="wishwzp"></constant>
 9  
10 </struts>

wishwzp.properties文件内容:(这个是默认的)

  userName=\u7528\u6237\u540d
  password=\u5bc6\u7801
  login=\u767b\u5f55
  welcomeInfo=\u6b22\u8fce{0}

wishwzp_zh_CN.properties文件内容:(这个是中文的)

  userName=\u7528\u6237\u540d
  password=\u5bc6\u7801
  login=\u767b\u5f55
  welcomeInfo=\u6b22\u8fce{0}

wishwzp_en_US.properties文件内容:(这个是英文的)

  userName=userName
  password=password
  login=login
  welcomeInfo=welcome{0}

上面的\u7528\u6237\u540d(“用户名”中文转Unicode为“\u7528\u6237\u540d”)

    \u5bc6\u7801(“密码”中文转Unicode为“\u5bc6\u7801”)

    \u767b\u5f55(“登录”中文转Unicode为“\\u767b\u5f55”)

    \u6b22\u8fce(“欢迎”中文转Unicode为“\u6b22\u8fce”)

都是采用unicode的

Unicode转换工具百度Unicode编码转换 - 站长工具

 

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 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 8 <title>Insert title here</title>
 9 </head>
10 <body>
11 <table>
12     <tr>
13         <td><s:text name="userName"></s:text></td>
14         <td>
15             <input type="text"/>
16         </td>
17     </tr>
18     <tr>
19         <td><s:text name="password"></s:text></td>
20         <td>
21             <input type="text"/>
22         </td>
23     </tr>
24     <tr>
25         <td>
26             <input type="button" value="<s:text name='login'></s:text>"/>
27         </td>
28     </tr>
29 </table>
30 </body>
31 </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 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 8 <title>Insert title here</title>
 9 </head>
10 <body>
11 <s:text name="welcomeInfo">
12     <s:param>Jack</s:param>
13 </s:text>
14 </body>
15 </html>

 

转载于:https://www.cnblogs.com/wishwzp/p/5472434.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值