在struts.xml里面加入:
<constant name="struts.custom.i18n.resources" value="globalMessages" />
如下:
<?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="globalMessages" /> 多个配置文件以逗号分割,资源文件不在根目录时,要添加相对路径,value中的值不能带.properties。
<package name="test" namespace="/test" extends="struts-default">
<!-- 国际化支持 -->
<action name="i18n" class="com.test.web.HelloAction">
<result name="success">/hello.jsp</result>
</action>
</package>
</struts>
myeclipse在src下新建
globalMessages_zh_CN.properties
hello=\u4F60\u597D\u4E16\u754C
globalMessages_en_US.properties
hello=Hello World\!
hello.jsp中可以输出
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>test</title>
</head>
<body>
${param.username}
${param.votedate}
<br/>
<s:text name="hello"/>
<br/>
通过request获取:${requestScope.hello}
</body>
</html>
HelloAction.java里面execute方法可以将hello获取到,并加入大request对象中
public String execute() throws Exception {
this.message="成功登陆";v
ActionContext.getContext().put("hello", this.getText("hello");
System.out.println(this.getText("hello"));
return "success";
}
<constant name="struts.custom.i18n.resources" value="globalMessages" />
如下:
<?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="globalMessages" /> 多个配置文件以逗号分割,资源文件不在根目录时,要添加相对路径,value中的值不能带.properties。
<package name="test" namespace="/test" extends="struts-default">
<!-- 国际化支持 -->
<action name="i18n" class="com.test.web.HelloAction">
<result name="success">/hello.jsp</result>
</action>
</package>
</struts>
myeclipse在src下新建
globalMessages_zh_CN.properties
hello=\u4F60\u597D\u4E16\u754C
globalMessages_en_US.properties
hello=Hello World\!
hello.jsp中可以输出
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>test</title>
</head>
<body>
${param.username}
${param.votedate}
<br/>
<s:text name="hello"/>
<br/>
通过request获取:${requestScope.hello}
</body>
</html>
HelloAction.java里面execute方法可以将hello获取到,并加入大request对象中
public String execute() throws Exception {
this.message="成功登陆";v
ActionContext.getContext().put("hello", this.getText("hello");
System.out.println(this.getText("hello"));
return "success";
}