struts2学习之国际化(十)

struts2国际化

  1. 配置struts2.xml文件支持国际化
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
<!-- 引入国际化支持 -->
  <constant name="struts.custom.i18n.resources" value="newbeedaly"></constant>

</struts>
  1. 配置property文件,中文,英文等

newbeedaly.property文件

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

newbeedaly_zh_CN.property文件

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

newbeedaly_en_US.property文件

userName=userName
password=password
login=login
welcomeInfo=welcome{0}
  1. 新建jsp页面,引入struts标签库,获取国际化数据,另外,struts2也支持调用jsp页面的欢迎信息
    login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<table>
    <tr>
        <td><s:text name="userName"></s:text></td>
        <td>
            <input type="text"/>
        </td>
    </tr>
    <tr>
        <td><s:text name="password"></s:text></td>
        <td>
            <input type="text"/>
        </td>
    </tr>
    <tr>
        <td>
            <input type="button" value="<s:text name='login'></s:text>"/>
        </td>
    </tr>
</table>
</body>
</html>

welcome.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<s:text name="welcomeInfo">
    <s:param>Jack</s:param>
</s:text>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值