java - <fmt :setLocale value ="${param.locale }" scope ="session"/>tag is not used

标签 java jsp localization

我用MyEclipse编译我的程序,我想实现国际化,所以我选择使用fmt标签。

代码如下:

<fmt:setLocale value="${param.locale }" scope="session" />

书上说${param.locale }可以得到浏览器的default-language。为了改变语言,我使用了两种语言,英语和中文。虽然我将浏览器的default-language设置为英文,但是当我重新加载jsp页面时,语言总是中文。你能告诉我这是怎么回事吗?

完整代码:

<%@ taglib prefix="fmt" uri="java.sun.com/jsp/jstl/fmt"; %> 
<fmt:setLocale value="${param.locale }" scope="session" /> <fmt:setBundlebasename="loginpage"/> <input type="text" id="text1" /> <br/> <input type="password" id="text2" /> <br /> <input type="submit" id="smb" value="<fmt:message key="login_sub" />" />     

最佳答案

不,那不是真的。 EL param 对象将请求参数名称映射到单个值。如果 param.locale 存在,那么您可以通过 fmt:setLocale/> 标签设置 locale

本文正文 - Formatting and internationalization through custom tags

The locale used by the JSTL tags when formatting data is normally determined by examining the Accept-Language header sent by a user's browser as part of each HTTP request. If no such header is present, then JSTL provides a set of JSP configuration variables you can set to specify a default locale. If these configuration variables have not been set, then the JVM's default locale is used, which is obtained from the operating system the JSP container is running on.

并查看 SO 线程 - How to set JSTL locale from Java code?

关于java - <fmt :setLocale value ="${param.locale }" scope ="session"/>tag is not used,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13946946/

相关文章:

java - eclipse EE juno : java.net.bind 异常

localization - 使用 PoEditor 添加翻译

JavaFX 应用程序显示奇怪的符号而不是俄语

java - 如何编译我的 Java 源文件

java - Java,如何在单击按钮时在两个图像之间交替,然后在再次单击时停止?

Java FX 应用程序加载事件

javascript - 在跨度的 onclick 事件提交表单时,如何避免浏览器发出确认消息?

java - 如何告诉编译器 Java 函数在被重写时必须被调用?

java - 使用 Dandelion DataTables 创建表时出现异常

android - 如何更改动态Android应用程序的语言?