tag is not used-6ren"> tag is not used-我用MyEclipse编译我的程序,我想实现国际化,所以我选择使用fmt标签。 代码如下: 书上说${param.locale }可以得到浏览器的default-language。为了改变语言,我使-6ren">
gpt4 book ai didi

java - tag is not used

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:31:02 26 4
gpt4 key购买 nike

我用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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com