繁体   English   中英

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

[英]Unable to decode utf-8 using thai language?

这是我的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 im in trouble,delhi,???????_30.64741430_76.817313799

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

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

如果您在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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM