2016-07-06 127 views
0

我对所有欧洲国家以及日本,中国,韩国等少数几个亚洲国家都有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> 

的任何信息,如何解决这一问题?我如何正确编码?

回答

0

尝试添加给你的JSP

<%@ page language="java" pageEncoding="UTF-8"%> 
+0

它不是一个jsp page.It是虚拟机文件。 – Subham

+0

尽管相同的要求,看看http://forum.spring.io/forum/spring-projects/web/64372-setting-content-encoding-in-velocity –

0

的顶部,你需要为指定字符集日本,韩国和中国

For japanese try: charset=iso-2022-jp 
For korean try: charset=iso-2022-kr 
For chinese try: charset=big5 
+0

谢谢..我只有在发送时才发送此问题电子邮件给用户,那里也标题部分正确显示所有的亚洲语言,但身体得到grabled – Subham

+0

电子邮件客户端使用标题中定义的内容类型,而不是在元标记.... 所以你最安全的赌注是将身体内容即所有特殊字符转换为它们的HTML实体,您不必再担心头部Content-Type ... 使用在线转换器工具来转换您的内容>>> [示例转换工具](https://www.emailonacid.com/character-converter) – coolstoner

相关问题