index.jsp
<%@ page contentType="text/html; charset=UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h2><s:text name="user"/></h2>
<h2><s:property value="%{getText('user')}"/></h2>
<h2><s:property value="%{getText('city')}"/></h2>
</body>
</html>
message.properties
user=Anonymous
city={0}Anonymous{1}
message_zh_CN.properties
user=user=\u5F20\u7389\u9F99
city={0}北京{1}
message_en_US.properties
user=zyl
city={0}BeiKing{1}
I18nTest.java
package com.zyl.Test;
import java.text.MessageFormat;
import java.util.Locale;
import java.util.ResourceBundle;
import javax.annotation.Resource;
import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
public class I18nTest {
public static void main(String[] args) {
Locale defaultLocale = Locale.getDefault();
defaultLocale = Locale.US;
ResourceBundle bundle = ResourceBundle.getBundle("message",defaultLocale);
System.out.println(bundle.getString("user"));
String city = MessageFormat.format(bundle.getString("city"),
new String[] { "086", "010" });
System.out.println(city);
}
}
struts
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.custom.i18n.resources" value="message"></constant>
<package name="*" extends="struts-default">
<action name="*" class="">
<result>/{1}.jsp
</result>
</action>
</package>
</struts>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
struts国际化
原创
©著作权归作者所有:来自51CTO博客作者mb6444ed45406a4的原创作品,请联系作者获取转载授权,否则将追究法律责任

提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
华为云引领首个代码大模型国际标准立项
该项目由中国信通院牵头,联合华为云等产学研机构共同提出,这也是国际上首个代码大模型的标准项目。
软件工程 人工智能 代码生成 codearts snap -
struts2国际化小结
一、底层是如何运作的 1、如何获得当前JDK系统已经提供的国家语言的支持 Locale[] loca
XML JDK 框架 bundle 配置文件