0

由于 struts 2 的默认 I18nInterceptor 在系统分发时会失败,因此我实现了一个基于 cookie 的解决方案。我添加了一个拦截器,用于查找 request_locale 参数并设置 cookie。它还寻找cookie。如果 request_locale 参数出现或 cookie 存在,我设置新的语言环境。这个拦截器是在struts 的I18N 拦截器之后调用的。但设置后,我没有看到语言发生变化。下面是我的拦截器的拦截方法。

public String intercept(ActionInvocation invocation) throws Exception {

    HttpServletRequest request = ServletActionContext.getRequest();
    String localeStr = request.getParameter("request_locale");
    if (localeStr != null) {
        setLocaleInCookie(localeStr);
    }
    if (localeStr == null) {
        localeStr = getLocaleFromCookie();
    }

    if (localeStr != null) {
        ActionContext.getContext().setLocale(new Locale(localeStr));
    }

    return invocation.invoke();
}

我想知道我这样做是否正确。有没有其他解决方案或解决方法?

4

0 回答 0