0

The JSTL formatting library: http://java.sun.com/jsp/jstl/fmt doesn't work at all if there is no Accept-Language header. can anyone explain why this is and how to get around it (Except for providing the header)

For instance: will format the date through a normal web browser, but using telnet or curl to request the page it doesn't format it correctly.

Matt Fellows
  • 6,512
  • 4
  • 35
  • 57
  • possible duplicate of [How to set JSTL locale from Java code?](http://stackoverflow.com/questions/6126542/how-to-set-jstl-locale-from-java-code) – anotherdave May 13 '14 at 13:13
  • Maybe a duplicate for the second half of my question, the first part still remains unanswered. Why, if I don't have that header in the request, do I not get any formatting, what-so-ever? – Matt Fellows May 13 '14 at 14:02

1 Answers1

1

As to why this is happening, this seems to be expected behaviour.

As per the JSTL spec on the Oracle site:

9.9 <fmt:formatDate>

Null & Error Handling

  • If value is null, remove the scoped variable if it is specified (see attributes var and scope).
  • If timeZone is null or empty, it is handled as if it was missing.
  • If this action fails to determine a formatting locale, it uses java.util.Date.toString() as the output format.

So as per your error, if no locale is set on the server-side & the request also doesn't pass one either, JSTL is falling back to a toString() call on the date, rather than e.g. the locale of the JVM settings.

anotherdave
  • 6,656
  • 4
  • 34
  • 65
  • At the risk of shooting the messenger: Why, if I specify a pattern, does it give a fish about locale. (Thanks for digging this out of the spec for me) – Matt Fellows May 14 '14 at 11:09
  • I know what you mean, especially if you've specified, e.g. "dd-mm-yy", it should be valid fairly universally. Maybe the thinking is for day/month names used in patterns, though still not a reason not to fall back to the JVM values – anotherdave May 14 '14 at 12:23