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
  •  | 
  •  

문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top