The JSTL formatting library: `http://java.sun.com/jsp/jstl/fmt` doesn't work at all if there is no `Accept-Language` header

StackOverflow https://stackoverflow.com/questions/23627158

  •  21-07-2023
  •  | 
  •  

Question

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.

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top