Velocity模板似乎因UTF-8而失败 [英] Velocity templates seem to fail with UTF-8

查看:103
本文介绍了Velocity模板似乎因UTF-8而失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用具有以下内容的速度模板:

I have been trying to use a velocity Template with the following content:

Sübjäct $item

除翻译两个Unicode字符外,其他所有内容都可以正常工作.打印在命令行上的结果字符串如下:

Everything works fine except the translation of the two Unicode characters. The result string printed on the command line looks like:

Sübjäct foo

我在速度网站和网络上搜索了此问题,并提出了不同的字体编码选项,这些选项已添加到我的代码中.但是这些无济于事.这是实际的代码:

I searched the velocity website and the web for this issue, and came up with different font encoding options, which I added to my code. But these don't help. This is the actual code:

velocity.setProperty("file.resource.loader.path", absPath);
velocity.setProperty("input.encoding", "UTF-8");
velocity.setProperty("output.encoding", "UTF-8");

Template t = velocity.getTemplate("subject.vm");
t.setEncoding("UTF-8");

StringWriter sw = new StringWriter();

t.merge(null, sw);       
System.out.println(sw.getBuffer());

我该如何解决此问题?

推荐答案

您是否尝试过使用这种语法?

Have you tried using this syntax?

Template template = Velocity.getTemplate("subject.vm", "UTF-8");

看起来应该做正确的事.

这篇关于Velocity模板似乎因UTF-8而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆