问题描述
我正在尝试使用Freemarker打印带重音符号的字符,但是在带重音字符的位置上,我仅收到问号.我已验证,以下陈述成立:
I am trying to print accented characters with Freemarker, but in the place of accented characters, I get only question marks. I have verified, that following statement holds:
"UTF-8" == Environment.getCurrentEnvironment().getConfiguration().getDefaultEncoding()
我可以很容易地看到,在将重音符号提供给模板之前,重音字符已正确保存在变量中.
I can easily see, that the accented characters are correctly held in the variable before giving it to the template.
我的freemarker上下文可以在这里找到: https://gist.github.com/1975239
My freemarker context can be found here: https://gist.github.com/1975239
例如,而不是:
Jedinečný živý koncert, kde nejen, že uslyšíte, ale i uvidíte splynutí metalové kapely s padesátičlenným orchestrem včetně.
我不断得到:
Jedine?ný ?ivý koncert, kde nejen, ?e usly?íte, ale i uvidíte splynutí metalové kapely s padesáti?lenným orchestrem v?etn?.
谢谢.
推荐答案
FreeMarker始终将文本视为UNICODE,因此不会生成问号.由于带重音的字母不是来自模板(如果我理解得很好),它一定是您的输出编码不正确.另请参见: http://freemarker.org/docs/app_faq.html#faq_questionmark
FreeMarker always treats text as UNICODE, so it doesn't generate question marks. Since the accented letters aren't coming from the templates (if I understand it well), it must be your output encoding that's improper. See also: http://freemarker.org/docs/app_faq.html#faq_questionmark
顺便说一句,getDefaultEncoding()
在这方面没有作用.这会影响加载模板时使用的解码,但是您说的是带重音的字符不是来自模板文件,我也不认为您可以从解码中得到?
-s(除非,对于无效的UTF而言) -8个字节的序列).从输出的编码开始,FreeMarker仅使用Writer
(而不是OutputStream
),因此它不会对此产生影响.
BTW, getDefaultEncoding()
has no role in this. That influences the decoding used when you load the templates, but you are saying that the accented characters aren't coming from the template file, also I don't think you can get ?
-s from decoding (unless, for invalid UTF-8 byte sequences). As of the encoding of the output, FreeMarker just uses a Writer
(as opposed to an OutputStream
), so it can't influence that.
这篇关于Freemarker编码-用问号代替重音符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!