在我的应用程序中,我必须根据用户在配置页面中选择的区域设置来显示内容。我没有使用浏览器默认区域设置。
使用<s:text>
时,它总是使用默认的资源文件。
在 Struts1 中,我使用以下代码在过滤器中设置默认区域设置
session.setAttribute("org.apache.struts.action.LOCALE",locale);
如何在 Struts2 中动态设置用户选择的区域设置?
最佳答案
这对我有用:
String language = userLocale.substring(0, 2);
String country = userLocale.substring(3, 5);
Locale locale = new Locale(language, country);
ActionContext.getContext().setLocale(locale);
session.put(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE, locale);
其中userLocale
的值的形式为:fr_FR,资源文件名为resource_fr_FR.properties
关于java - 如何通过 Struts 2 中的代码动态设置区域设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18509523/