JSTL formatDate ignore language

I want to localize dates from JSTL and I am trying to do it like below.

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<fmt:setLocale value="da_DK" scope="application" />
<fmt:formatDate value="${some.date}" dateStyle="FULL" />

      

some.date

is an instance java.util.Date

. I've played with different languages ​​but nothing seems to work. I get the following output no matter what language I choose: Tuesday 13th January 2015. I also tried the following, after removing the above call setLocale()

:

<jsp:useBean id="now" class="java.util.Date" />

<fmt:setLocale value="en_US" />
<fmt:formatDate value="${now}" dateStyle="FULL" />

<fmt:setLocale value="fr_FR" />
<fmt:formatDate value="${now}" dateStyle="FULL" />

      

The above exits on Tuesday, Jan 13, 2015 twice, and the same happens for every locale I've tried. The only thing I've configured related to locale is the following (Spring MVC project):

@Bean
public CookieLocaleResolver localeResolver() {
    Locale locale = new Locale("dk");

    CookieLocaleResolver localeResolver = new CookieLocaleResolver();
    localeResolver.setDefaultLocale(locale);

    return localeResolver;
}

      

Shouldn't the text be translated into the language defined in the locale, or the format at least changed? Any ideas what I am doing wrong here? I've tried every example I can find on the internet, but the result is the same.

+3


source to share


1 answer


I would just change the scope to session

like below



<fmt:setLocale value="fr_FR" scope="session"/>

Date in France:
<fmt:formatDate value="${now}" dateStyle="full"/> <br/>

<fmt:setLocale value="en_US" scope="session"/>
 Date in US: 
<fmt:formatDate value="${now}" dateStyle="full" /> <br/>

      

+3


source







All Articles