Details
-
Bug
-
Status: Closed
-
Normal
-
Resolution: Fixed
-
None
-
None
-
None
-
Flagged
-
Quasar
-
Quasar Sprint 312
-
Undetermined
-
Small (1-2)
Description
In Tomcat, when you call response.setContentType("application/json") without explicitly setting the character encoding, the default character encoding of ISO-8859-1 is used. However, the default character encoding is not appended to the content type when you call response.getContentType().
So, if you haven't explicitly called response.setCharacterEncoding() to set a different character encoding, the returned value of response.getContentType() will be "application/json" without the character encoding appended.
However, if you explicitly invoke response.setCharacterEncoding("UTF-8"), then the character encoding "UTF-8" will be appended to the content type when you call response.getContentType(), resulting in "application/json;charset=UTF-8".
It turned out that in PageInfoRenderingValve#writeResponse we did never do something like
response.setCharacterEncoding(pageInfo.getCharacterEncoding());
before setting the content type on the response, and as a result, when the page would come from cache, it does not use the original charset but the default UTF-8 from the HST. With this fix we make sure that
- We still have the default response encoding is UTF-8
- If the HST rendering for some reason overrides the encoding, it also works for cached pages