JSP 页面中的语言检索是如何工作的?

How it work the language retrieval in this JSP page?

我是 JSP 开发的新手,我有以下疑问。在我正在处理的一个非常古老的遗留项目的旧 JSP 页面中,我可以找到以下几行:

<%
    String language = (String) javax.servlet.jsp.jstl.core.Config.get(request.getSession(), javax.servlet.jsp.jstl.core.Config.FMT_LOCALE);
%>

因此查看变量名称 (language) 并使用调试器,我很清楚它包含页面语言(在我的特定情况下 language 变量是 it 表示意大利语。

我的疑惑是:前面的代码到底是做什么的?从什么检索语言值?是浏览器语言还是什么?

它是在服务器(而非浏览器)上为当前用户会话定义的语言。通过阅读 Config:

的正确 javadoc 可以注意到这一点

Config#get(HttpSession session, String name

Looks up a configuration variable in the "session" scope.

The lookup of configuration variables is performed as if each scope had its own name space, that is, the same configuration variable name in one scope does not replace one stored in a different scope.

Config#FMT_LOCALE

Name of configuration setting for application- (as opposed to browser-) based preferred locale