HttpServletRequest getLocale返回OS语言环境而不是浏览器语言环境 [英] HttpServletRequest getLocale returns OS locale not browser locale

查看:1953
本文介绍了HttpServletRequest getLocale返回OS语言环境而不是浏览器语言环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  @Override 
public void onRequestStart(HttpServletRequest请求,
HttpServletResponse响应){
currentIP = request.getRemoteAddr();
setLocale(request.getLocale());
handle.set(this);
this.request = request;
this.response = response;
}

但是,request.getLocale()返回 en_US ,这是我的操作系统区域设置。但是,在Firefox插件切换语言环境( https:/ /addons.mozilla.org/cs/firefox/addon/quick-locale-switcher/?src=userprofile ),我已经将它设置为 cs_CZ getLocale()仍然会返回 en_US

获取会话语言环境:
$ b $ pre $ UI.getCurrent()。getSession()。getLocale();

这对我有用。


I am using vaadin framework and in my application I have:

@Override
public void onRequestStart(HttpServletRequest request,
        HttpServletResponse response) {
    currentIP = request.getRemoteAddr();
    setLocale(request.getLocale());
    handle.set(this);    
    this.request = request;    
    this.response = response;
}

however, request.getLocale() returns en_US, which is my OS locale. However, in Firefox addon for switching locales (https://addons.mozilla.org/cs/firefox/addon/quick-locale-switcher/?src=userprofile), I have set up it to be cs_CZ, however, getLocale() will still return en_US.

解决方案

Try getting the session locale:

UI.getCurrent().getSession().getLocale();

That worked for me.

这篇关于HttpServletRequest getLocale返回OS语言环境而不是浏览器语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆