Struts2 中 Requestprocessor.processLocale 方法的等价物是什么?

what is the equivalent of Requestprocessor.processLocale method in Struts2?

我是 Struts 2 的新手,我正在努力将 Struts 1 代码迁移到 Struts 2,在这种情况下,Action Servlet 已扩展并在扩展class "process"方法,在请求中设置locale,如下所示,

public class TestServlet extends ActionServlet  {

    protected void process(HttpServletRequest request, HttpServletResponse response)
                    throws IOException, ServletException {
            Locale locale = Locale.ENGLISH;
        locale = Locale.FRENCH;
        request.setAttribute("_locales", locale);

        super.process(request, response);

    }

}

我如何迁移此更改以在 struts 2 中工作。Struts 2 中的等效方法是什么?

在 Struts2 中,您不再需要 actionservlet 或请求处理器,一切都通过 i18n 拦截器完成。

希望您能在 this 答案中找到帮助。

The Struts2 internationalization interceptor i18n could be used to dynamically change the current user locale to the user specific locale for the user's session.

"Or, alternatively, only for the current request (since XWork 2.1.3)"

通过发出 HTTP 请求并提供请求参数 request_locale 具有像 "en_US" 这样的语言环境的值,它创建 美国英语语言环境。

此语言环境默认保存在会话中 "WW_TRANS_I18N_LOCALE" 属性并用作当前语言环境 用户会话。当前语言环境也被推入 此拦截器根据每个请求映射 ActionContext。这允许 支持本地化的框架组件都利用 ActionContext 的语言环境。


此外,如果您想了解如何获取当前语言环境,您应该阅读我对 Get user locale detected by i18n interceptor in action class 的回答。