0

我在 ZK 中有一个使用 Spring-security 的程序。我为该网络程序提供了三种语言。当用户登录时,我想从数据库中检索他的语言并以该用户的语言在网站中设置网站。我找到了一个解决方案,将它放在doAfterCompose(Component comp)我的页面控制器中:

Locale currentLocale = (Locale) Executions.getCurrent().getSession().getAttribute(Attributes.PREFERRED_LOCALE);
        Locale userLocale = user.getLocale();
        if (currentLocale == null || !currentLocale.equals(userLocale)) {
            Executions.getCurrent().getSession().setAttribute(Attributes.PREFERRED_LOCALE, user.getLocale());
            Executions.sendRedirect(null);
        }

但我认为这不是一个好的解决方案,因为当用户登录时,页面会刷新两次。首先它以英语显示,然后以用户的语言重新加载。这种行为是正常的,因为我把它放在我的代码中,但我想要一个更好的解决方案来检索登录用户语言的页面。

4

1 回答 1

0

我认为你可以使用

 Executions.getCurrent().getHeader("accept-language")
于 2013-07-25T10:54:39.777 回答