Re: Freemarker Encoding issue
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Tuesday, March 9, 2010, 4:54:58 AM, Zhiqiang Huang wrote:
> I tried as you say, ${"\x6464"} is still output as a '?'. And I
> have debug my servlet to make sure that the string in java is
> correct, i.e., do not contain any '?'.
> So I want to know how should I set the configuration for FreeMarker and java.io.Writer?
The Writer is not controlled by FreeMarker as it just receives the
Writer from outside, so it has no power to configure it. But see
ServletResponse.setCharacterEncoding(). However, if you are using
FreemarkerServlet, then you can set it there, as you can see on
http://freemarker.org/docs/pgui_misc_servlet.html#pgui_misc_servlet_model2
if you are searching for "UTF-8" there.
> Thank you.
>
> Best regards,
> hzqtc
>
> On Tue, Mar 9, 2010 at 6:38 AM, Daniel Dekany <[email protected]> wrote:
>
> Monday, March 8, 2010, 5:30:23 PM, Zhiqiang Huang wrote:
>
>> Hi, there
>>
>> I'm new to freemarker and I'm using freemarker with servlet. I'm coming across a encoding issue.
>> If I put chinese in .ftl, it can be output correctly. But when I
>> put chinese in data-model (a hashmap), it can't. The Chinese characters are output as '?'.
>> I have tried all the setxxxEncoding methods to set the encoding to "utf-8" and failed.
>> Could anyone help me? Thank you very much!
>
> Put a ${"\x6464"} into your template. If in the browser it shows a "?"
> instead of a chinese character, then something is still wrong with the
> FreeMarker configuration and/or with the java.io.Writer where
> FreeMarker prints its output. If ${"\x6464"} shows a chinese
> character, and also the chiense text entered directly into the
> template shows correctly, then most probably it's the connection to
> the data-base server that has an encoding issue. (You can double-check
> that if in Java (not in FreeMarker) you log the character codes of the
> string... if it contains 63-s, which is the code of '?', the it
> already contains the '?'-s when you receive it from the database.)
>
>> Best wishes,
>> hzqtc
> --
> Best regards,
> Daniel Dekany
>
--
Best regards,
Daniel Dekany
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev