簡體   English   中英

字符編碼不適用於日語,中文和韓語

[英]Character Encoding not working for Japanese ,Chinese and Korean

我為所有歐洲國家和一些亞洲國家(例如日本,中國,韓國)使用Unicode字符。 除日本,中國,韓語外,所有Unicode都適用於歐洲國家/地區。

日本的示例:

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);

在調試合並方法時,我發現對於中文,日文,韓文來說,合並結果本身就在這里被抓住。

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 language="java" pageEncoding="UTF-8"%>

您需要指定日文,韓文和中文的字符集

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM