Reputation: 137
I use MyEclipse to compile my program,and I want to achieve internationalization, so I choose use the fmt
tag.
The follow is the code:
<fmt:setLocale value="${param.locale }" scope="session" />
Book says that ${param.locale }
can get the browser's default-language
. In order to change the language, I use two languages, English and Chinese. Though I set the browser's default-language
to English, when I reload the jsp page, the language is always Chinese. Could you tell me what's the matter?
full codes:
<%@ 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" />" />
Upvotes: 3
Views: 7945
Reputation: 94643
No that's not true. The EL param
object maps a request parameter name to a single value. If param.locale
exists then you can set locale
through fmt:setLocale/>
tag.
Text from this article - 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.
and take a look at SO thread - How to set JSTL locale from Java code?
Upvotes: 2