Niranjan Kumar
Niranjan Kumar

Reputation: 869

Default locale is not getting set to UK using <fmt:setLocale value="en_GB" />

I am setting the default locale to UK using in jsp but its not reflecting. Why is this so? Is there any other way to do this or can I do this from Java end?

Thank you for your response

Upvotes: 0

Views: 2057

Answers (3)

Andre
Andre

Reputation: 691

If you are having problems with fmt:formatDate you should specify the timezone, e.g.

<fmt:formatDate value="${myDate}" pattern="dd MMM HH:mm" timeZone="BST"/>

Values for timeZone you can get from java.util.TimeZone.getAvailableIDs()

Edit

Try using the javax.servlet.jsp.jstl.core.Config class:

Config.set(getServletContext(), Config.FMT_LOCALE, "en_GB");

Upvotes: 0

J&#246;rn Horstmann
J&#246;rn Horstmann

Reputation: 34034

If by "default locale" you mean actually calling java.util.Locale.setDefault() then this is not possible in jstl since it would affect the whole application and not just the user acessing the current page. The fmt:setLocale tag sets the locale for the pages LocalizationContext which is then used by fmt:message, fmt:formatNumber, fmt:parseNumber, fmt:formatDate, and fmt:parseDate.

Upvotes: 0

BalusC
BalusC

Reputation: 1109302

You need to call <fmt:setLocale> before <fmt:setBundle>.

<fmt:setLocale value="en_GB" />
<fmt:setBundle basename="com.example.i18n.text" />

If you call it afterwards, it would have no effect because the bundle is already loaded at that point.

See also:

Upvotes: 2

Related Questions