<%@ page import="java.util.Enumeration, java.util.Locale" %> <%@ page import="javax.servlet.jsp.jstl.core.Config" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> JSTL: Formatting/I18N Support -- Demo Example

Demo

The following bundles exist in the web application: 'Resources', 'Resources_de', 'Resources_fr', 'Resources_it'. 'Resources' is the 'base' bundle and contains all messages in English. The italian bundle only holds one message (key=greetingMorning).

<% Config.set(request, Config.FMT_FALLBACK_LOCALE, request.getParameter("fallback")); %>
Set application-based locale: FrenchGermanItalianSpanish (no bundle)None
Set fallback locale: FrenchGermanItalianSpanish (no bundle)None

Request parameter "locale":
(This value is used to set the application based locale for this example)

Application based locale: <%=Config.find(pageContext, Config.FMT_LOCALE)%>
(javax.servlet.jsp.jstl.fmt.locale configuration setting)

Browser-Based locales: <% Enumeration enum_ = request.getLocales(); while (enum_.hasMoreElements()) { Locale locale = (Locale)enum_.nextElement(); out.print(locale); out.print(" "); } %>
(ServletRequest.getLocales() on the incoming request)

Fallback locale: <%=Config.find(pageContext, Config.FMT_FALLBACK_LOCALE)%>
(javax.servlet.jsp.jstl.fmt.fallbackLocale configuration setting)

KEY VALUE
greetingMorning
greetingEvening
currentTime
serverInfo
undefinedKey