The JSTL <fmt:setLocale> Formatting Tag is used for setting the locale configuration variable with the given locale.
Syntax:
<fmt:setLocale value=”localeValue” />
fmt:setLocale tag attributes:
Attribute | Description | Required |
value | It specify a two-part code that represents the ISO-639 language code and an ISO-3166 country code. | Yes |
variant | It specify the browser specific variant. | No |
scope | It specify the scope of the locale configuration variable. | No |
Example:
test.jsp
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <html> <head> <title>fmt:setLocale JSTL formatting tag example</title> </head> <body> <fmt:bundle basename="com.w3spoint.properties.message"> <fmt:message key="message.first"/><br/> <fmt:message key="message.second"/><br/> <fmt:message key="message.third"/><br/> </fmt:bundle> <h4>Message after changing the locale.</h4> <fmt:setLocale value="en"/> <fmt:bundle basename="com.w3spoint.properties.message"> <fmt:message key="message.first"/><br/> <fmt:message key="message.second"/><br/> <fmt:message key="message.third"/><br/> </fmt:bundle> </body> </html> |
message_en_US.properties
message.first = This is first message using en_US locale. message.second = This is second message en_US locale. message.third = This is third message en_US locale. |
message_en.properties
message.first = This is first message using en locale. message.second = This is second message using en locale. message.third = This is third message using en locale. |
web.xml
<web-app> <welcome-file-list> <welcome-file>test.jsp</welcome-file> </welcome-file-list> </web-app> |
Output:
Download this example.
Next Topic: JSTL fmt:timeZone Formatting Tag with example.
Previous Topic: JSTL fmt:setBundle Formatting Tag with example.