struts 国际化

struts.xml 
    <constant name="struts.custom.i18n.resources" value="res"/>
    <constant name="struts.i18n.encoding" value="UTF-8"/>
    <constant name="struts.i18n.reload" value="true"/>




<package name="reg" extends="struts-default" namespace="/">
<action name="show" class="com.action.RegAction" method="show"/>


<action name="reg" class="com.action.RegAction">
   <result>success.jsp</result>
   <result name="input">/index.jsp</result>
</action>
   </package>


全局国际化项目(程序级)
resources/res.properties   1
resources/res_en.properties
resources/res_en_US.properties1
resources/res_zh.properties
resources/res_zh_CN.properties1
resources/res_zh_TW.properties1




intellij idea 配置直接保存unicode编码  
Settings->Editor->File Encodings
在下边设置 
Default encoding for properties files:UTF-8  选中 Transparent native-toascii conversion


#------ res_zh_CN.properties
reg.title = 用户注册系统
reg.name = 姓名
reg.name.null = 用户姓名不能为空,必须填写!!!
reg.age = 年龄
reg.submit = 提交注册




#------ res_en_US.properties
reg.title = User Register System Ver1.0
reg.name = UserName
reg.name.null = username must not be empty!!!
reg.age = UserAge
reg.submit = SubmitReg




jsp 文件如何显示国际化信息  <s:text name="reg.name"/>


<%@ page language="java" pageEncoding="utf-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Struts 2.5.10 数据类型转换</title>
    <style>
        input{padding:5px;margin:5px;}
    </style>
</head>
<body>
<s:debug/>
<h3><s:text name="reg.title"/></h3>
<form action="reg" method="post">
    <s:text name="reg.name"/> : <input type="text" name="name">${fieldErrors['name'][0]}<br>
    <s:text name="reg.age"/>: <input type="text" name="age">${fieldErrors['age'][0]}<br>
    <input type="submit" value="<s:text name="reg.submit"/>"><br>
</form>
</body>
</html>


action 控制器
继承mport com.opensymphony.xwork2.ActionSupport;   有getText() 直接读取国际化

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值