java - struts2 中的多个应用程序属性,需要根据某些条件更改 java 中的属性文件?

标签 java struts2 resourcebundle

我正在使用

struts.custom.i18n.resources=file1,file2

file1(ApplicationResources1.properties)

enter.user = User name

file2(ApplicationResources2.properties)

enter.user = User name1

根据某些情况,我需要将文件从 file1 切换到 file2。? 我使用了以下代码...两个文件都已加载,但我需要根据条件引用这些文件中的任何一个...

Struts.xml
<constant name="struts.custom.i18n.resources"
    value="ApplicationResources2,ApplicationResources1" />

Test.java

if(condition){
    LocalizedTextUtil.clearDefaultResourceBundles();
LocalizedTextUtil.addDefaultResourceBundle("ApplicationResources1.properties");
LocalizedTextUtil.setReloadBundles(true); 
}else{
    LocalizedTextUtil.clearDefaultResourceBundles();
LocalizedTextUtil.addDefaultResourceBundle("ApplicationResources2.properties");
LocalizedTextUtil.setReloadBundles(true); 
}

最佳答案

如果您的属性文件名称是 ApplicationResources1.propertiesApplicationResources2.properties 那么您需要在 addDefaultResourceBundle 方法中使用这些名称 LocalizedTextUtil.

if(condition) {
  LocalizedTextUtil.clearDefaultResourceBundles();
  LocalizedTextUtil.addDefaultResourceBundle("ApplicationResources1");
  LocalizedTextUtil.setReloadBundles(true); 
}else {
  LocalizedTextUtil.clearDefaultResourceBundles();
  LocalizedTextUtil.addDefaultResourceBundle("ApplicationResources2");
  LocalizedTextUtil.setReloadBundles(true); 
}

关于java - struts2 中的多个应用程序属性,需要根据某些条件更改 java 中的属性文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17161583/

相关文章:

java - 2d sprites 中 vbo 的高效使用[opengl/android]

jquery - Struts Jquery 插件对话框只会打开一次

struts2 - OGNL 异常设置 Struts2 复选框值

java - Firebase - 使用 ref B 的值从 ref A 获取值的最佳方法?

java - Commons IO 2.4,如何控制FileAlterationListener的状态并重启

symfony - 如何将特定文件添加到 assetic 中?

java - Google-App-Engine (Struts2) 中的资源包

捷克语 MessageResource.getMessage() 的 Spring ResourceBundleMessageSource 编码

java - 使用 ChartPanel 覆盖paintComponent

html - struts2 元素的布局页面出现不需要的边框