在web的根目录下建一个包用于放资源文件:
ApplicationResources.properties
ApplicationResources_en_US.properties
ApplicationResources_zh_CN.properties
ApplicationResources_en_US.properties 中的代码
- button_submit=submit
ApplicationResources_zh_CN.properties 中的代码
- button_submit=提交
在struts-config.xml中加如下代码:
struts-config.xml 中的代码
JSP 中的代码
在网站的欢迎页面中放置中英文转换的选择,可以用链接、单选框、下拉列表框等,如果FormBean里有个String类型的字段language用来接受这个被选择的值,那么在Action中的代码如下:
Action 中的代码
由于本例中用的资源文件名中还指定了国家,所以如果上面form.getLanguage() 的值为"zh",Action中的第2行代码最好用new Locale("zh", "CN")。