我在网上找了各种方法都试过,都不行,求大神帮忙,下面是我的代码:
额 你的图显示不出来么
我昨天刚做了struts2的国际化 不过没注意struts2 的版本 我是配置了了个I18N的配置 然后再配置文件中设置对应的值就可以了
在页面上用 你这样不行么
<?xml version="1.0" encoding="UTF-8"?>
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
struts2_test01
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Welcome file lists -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<!-- Add packages here -->
<constant name="struts.devMode" value="true"/>
<constant name="struts.ng.i18n.encoding" value="UTF-8"></constant>
<package name="action" namespace="/" extends="struts-default">
<default-action-ref name="index"></default-action-ref>
<action name="index" class="com.java.struts.index" method="add">
<result name="success">
/Hello.jsp
</result>
</action>
</package>
先在struts2配置文件中加这个配置
然后在你的根目录 也就是src下加两个properties文件
文件名 :
message_zh_CN.properties 这是中文的
message_en_US.properties 这是英文的
在配置文件中配置你的信息
在页面上用
这个标签取值
在后台代码中这样使用:
this.addFieldError("username", this.getText("这里的name是你配置文件中的key值"));
前提是你的action类继承了ActionSupport
这样就直接可以在页面上国际化了 当你切换自己浏览器的语言的时候 就可以看到对应的显示