无法使用泰语解码utf-8?

时间:2014-11-25 12:09:55

标签: java html encoder decoder

这是我的JSP页面:

<%-- 
    Document   : new jsp1
    Created on : Nov 24, 2014, 12:38:07 PM
    Author     : Java
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
 <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
 </head>
 <body>
   <%
   String msg="206_John_help i m in trouble,delhi,อินเดีย_30.64741430_76.817313799";
   String result = java.net.URLEncoder.encode(msg, "UTF-8");
   System.out.println("The msg is "+result);
   String result1=java.net.URLDecoder.decode(result, "UTF-8");
   System.out.println("The decoded msg is "+result1);

   %>
 </body>
</html>

输出为206_John_help i m in trouble,delhi,???????_30.64741430_76.817313799

我总是得到??????而不是泰语字母。如何在解码时获取泰语字母?

1 个答案:

答案 0 :(得分:1)

问题不在于编码和解码消息,而是在服务器容器中。似乎服务器无法正确显示特殊字符,因此无法从请求中处理它们。

如果在JSP页面本身显示值,一切正常。

示例:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
 <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
 </head>
 <body>
   <%
   String msg="206_John_help i m in trouble,delhi,อินเดีย_30.64741430_76.817313799";
   System.out.println("The original message "+msg);
   String result = java.net.URLEncoder.encode(msg, "UTF-8");
   System.out.println("The msg is "+result);
   String result1=java.net.URLDecoder.decode(result, "UTF-8");
   System.out.println("The decoded msg is "+result1);

   %>
   Original message <%=msg %><br />
   Encrypted message <%=result %> <br />
   Decrypted message <%=result1 %>
</body>
 </html>