Another JSTL gotcha

Another JSTL Gotcha.

JSTL‘s format date tag uses browser-based content negotiation to determine the locale of a site viewer so it can format the date correctly for that user’s language settings.

The only problem is that if you have specified a pattern to use to override the date format it ignores that in the face of the browsers’ language settings.

This could be a bug, the spec is not clear either way though.

I use that tag and a fixed pattern to build links in my blog archive. They work fine for me, but when a bot (that doesn’t specify a language) comes along the links get rewritten in a different format and the links break.

Took me a while to work out how that was all happening.

Anyway, the fix is to hard-code a language setting in the JSP as follows:

<fmt:setLocale value='en-gb'/>

What a palava!

Leave a Reply

Your email address will not be published. Required fields are marked *