0

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

Niranjan Kumar
  • 819
  • 1
  • 10
  • 15

3 Answers3

2

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

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");
Andre
  • 691
  • 3
  • 11
  • Thank you Andre but I am not having problem with fmt:formatDate I am unable to set my locale to UK which is showing some problem in fmt:formatNumber when the browser locale is changed to Polish. SO I want to make the locale default to UK – Niranjan Kumar Jan 06 '12 at 07:17
  • What happens when you try to set the Locale programmatically via `javax.servlet.jsp.jstl.core.Config.set(getServletContext(), Config.FMT_LOCALE, "en_GB");` – Andre Jan 06 '12 at 11:07
0

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.

Jörn Horstmann
  • 33,639
  • 11
  • 75
  • 118