1. <small id='fabW8'></small><noframes id='fabW8'>

      <i id='fabW8'><tr id='fabW8'><dt id='fabW8'><q id='fabW8'><span id='fabW8'><b id='fabW8'><form id='fabW8'><ins id='fabW8'></ins><ul id='fabW8'></ul><sub id='fabW8'></sub></form><legend id='fabW8'></legend><bdo id='fabW8'><pre id='fabW8'><center id='fabW8'></center></pre></bdo></b><th id='fabW8'></th></span></q></dt></tr></i><div id='fabW8'><tfoot id='fabW8'></tfoot><dl id='fabW8'><fieldset id='fabW8'></fieldset></dl></div>
        <bdo id='fabW8'></bdo><ul id='fabW8'></ul>

      <legend id='fabW8'><style id='fabW8'><dir id='fabW8'><q id='fabW8'></q></dir></style></legend>
      1. <tfoot id='fabW8'></tfoot>

        如何通过 Struts 2 中的代码动态设置语言环境

        How to set locale dinamically via code in Struts 2(如何通过 Struts 2 中的代码动态设置语言环境)
      2. <tfoot id='5hSfZ'></tfoot>
        <i id='5hSfZ'><tr id='5hSfZ'><dt id='5hSfZ'><q id='5hSfZ'><span id='5hSfZ'><b id='5hSfZ'><form id='5hSfZ'><ins id='5hSfZ'></ins><ul id='5hSfZ'></ul><sub id='5hSfZ'></sub></form><legend id='5hSfZ'></legend><bdo id='5hSfZ'><pre id='5hSfZ'><center id='5hSfZ'></center></pre></bdo></b><th id='5hSfZ'></th></span></q></dt></tr></i><div id='5hSfZ'><tfoot id='5hSfZ'></tfoot><dl id='5hSfZ'><fieldset id='5hSfZ'></fieldset></dl></div>
        <legend id='5hSfZ'><style id='5hSfZ'><dir id='5hSfZ'><q id='5hSfZ'></q></dir></style></legend>

          <tbody id='5hSfZ'></tbody>

            • <bdo id='5hSfZ'></bdo><ul id='5hSfZ'></ul>

                  <small id='5hSfZ'></small><noframes id='5hSfZ'>

                  本文介绍了如何通过 Struts 2 中的代码动态设置语言环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在我的应用程序中,我必须根据在配置页面中选择的语言环境用户显示内容.我没有使用浏览器默认语言环境.

                  In my application, I have to display the content based on the locale user chosen in the configuration page. I am not using browser default locale.

                  使用<s:text>时,总是使用默认资源文件.

                  when using <s:text>, it always use the default resource file.

                  在 Struts1 中,我使用下面的代码在我的过滤器中设置默认语言环境

                  In Struts1, I have used the below code to set default locale in my filter

                  session.setAttribute("org.apache.struts.action.LOCALE",locale);
                  

                  如何在 Struts2 中动态设置用户选择的语言环境?

                  How to set the user chosen locale dynamically in 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

                  where the values of userLocale are of the form : fr_FR and the file for the resources is named resource_fr_FR.properties

                  这篇关于如何通过 Struts 2 中的代码动态设置语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                  • <tfoot id='2uX0P'></tfoot>

                  • <small id='2uX0P'></small><noframes id='2uX0P'>

                    <i id='2uX0P'><tr id='2uX0P'><dt id='2uX0P'><q id='2uX0P'><span id='2uX0P'><b id='2uX0P'><form id='2uX0P'><ins id='2uX0P'></ins><ul id='2uX0P'></ul><sub id='2uX0P'></sub></form><legend id='2uX0P'></legend><bdo id='2uX0P'><pre id='2uX0P'><center id='2uX0P'></center></pre></bdo></b><th id='2uX0P'></th></span></q></dt></tr></i><div id='2uX0P'><tfoot id='2uX0P'></tfoot><dl id='2uX0P'><fieldset id='2uX0P'></fieldset></dl></div>

                          <bdo id='2uX0P'></bdo><ul id='2uX0P'></ul>
                            <tbody id='2uX0P'></tbody>
                          <legend id='2uX0P'><style id='2uX0P'><dir id='2uX0P'><q id='2uX0P'></q></dir></style></legend>