我对所有欧洲国家以及日本,中国,韩国等少数几个亚洲国家都有Unicode字符。除了日本,中国,韩国以外,所有Unicodes都适用于欧洲国家。不适用于日文,中文和韩文的字符编码
举例日本:
为中国dear_name=\u30c7\u30a3\u30fc\u30e9\u30fc
举例:
dear_name=\u4eb2\u7231\u7684
举例韩国:
dear_name=\uce5c\uc560\ud558\ub294
举例瑞典(这个是工作的罚款):
dear_name=Till
默认字符编码是UTF-8。
Template template = VelocityFactory.getTemplate("test.vm", "UTF-8");
String messageText = VelocityFactory.merge(context, template, charset);
在调试合并方法时,我发现合并的结果在中文,日文,韩文这里已经变成了grabled。
public static String merge(VelocityContext context, Template template, String charset) throws Exception {
String newResult = null;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
OutputStreamWriter streamWriter;
if(charset != null && charset.length() > 0) {
streamWriter = new OutputStreamWriter(outputStream, charset);
} else {
streamWriter = new OutputStreamWriter(outputStream);
}
template.merge(context, streamWriter);
streamWriter.close();
mergedResult = outputStream.toString();
outputStream.close();
return newResult;
}
}
以下是邮件模板,只为报头是在日本,中国和韩国的正确格式显示,而不是身体:
<html>
<head>
<meta http-equiv="Content-Type" content="$contentType">
</head>
<body>
<div id="content">
<table border="0" cellpadding="0" cellspacing="0" style="margin-left: 0px;">
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0" class="textBody" style="margin-bottom: 120px;">
<tr>
<td valign="bottom" class="mainHeader" nowrap>
$velocityUtils.getMessage("test")
</td>
</tr>
<tr>
<td colspan="2">
<img src="$imageBar" class="clipped">
</td>
</tr>
</table>
<div id="info" class="textBody">$velocityUtils.getMessage("test1")<br><br></div>
</td>
</tr>
</table>
</div>
</body>
</html>
的任何信息,如何解决这一问题?我如何正确编码?
它不是一个jsp page.It是虚拟机文件。 – Subham
尽管相同的要求,看看http://forum.spring.io/forum/spring-projects/web/64372-setting-content-encoding-in-velocity –