Struts2--国际化

  Struts对国际化的支持表现在三个地方:

  |-UI标签

  |-验证通知的消息和错误

  |-在action类里面通过getText()方法

   要实现Struts的国际化,首先,需要在struts.xml配置文件中加入如下配置:

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

然后在src文件夹下写两个用于实现国际化的配置文件

·fuwh_zh_CN.properties

city=u6b22u8fceu8001u5085u6765u5230u4e0au6d77{0}
name=u5ba2u670d

·fuwh_en_US.properties

city=welcome laofu to shanghai{0}
name=kefu

最后编写页面文件

复制代码
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ page import="java.util.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here</title>
</head>
<body>
    <s:text name="name"></s:text>:
    <s:text name="city">
        <s:param>888888</s:param>
    </s:text>
    <s:property value="getText('name')"/>
</body>
</html>
复制代码

这样就可以根据本地的语言环境来选择显示的内容了,实现国际化编程

原文地址:https://www.cnblogs.com/wangsicongde/p/7574274.html